Skip to content

Commit 2580f08

Browse files
committed
Rollup merge of rust-lang#24482 - GuillaumeGomez:error-explanation, r=alexcrichton
Part of rust-lang#24407.
2 parents fb88cca + 9a15234 commit 2580f08

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

src/librustc/diagnostics.rs

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,53 @@ reference when using guards or refactor the entire expression, perhaps by
112112
putting the condition inside the body of the arm.
113113
"##,
114114

115+
E0009: r##"
116+
In a pattern, all values that don't implement the `Copy` trait have to be bound
117+
the same way. The goal here is to avoid binding simultaneous by-move and by-ref.
118+
119+
This limitation may be removed in a future version of Rust.
120+
121+
Wrong example:
122+
123+
```
124+
struct X { x: (), }
125+
126+
let x = Some((X { x: () }, X { x: () }));
127+
match x {
128+
Some((y, ref z)) => {},
129+
None => panic!()
130+
}
131+
```
132+
133+
You have two solutions:
134+
1. Bind the pattern's values the same way:
135+
136+
```
137+
struct X { x: (), }
138+
139+
let x = Some((X { x: () }, X { x: () }));
140+
match x {
141+
Some((ref y, ref z)) => {},
142+
// or Some((y, z)) => {}
143+
None => panic!()
144+
}
145+
```
146+
147+
2. Implement the `Copy` trait for the X structure (however, please
148+
keep in mind that the first solution should be preferred!):
149+
150+
```
151+
#[derive(Clone, Copy)]
152+
struct X { x: (), }
153+
154+
let x = Some((X { x: () }, X { x: () }));
155+
match x {
156+
Some((y, ref z)) => {},
157+
None => panic!()
158+
}
159+
```
160+
"##,
161+
115162
E0162: r##"
116163
An if-let pattern attempts to match the pattern, and enters the body if the
117164
match was succesful. If the match is irrefutable (when it cannot fail to match),
@@ -278,7 +325,6 @@ See also https://github.com/rust-lang/rust/issues/14587
278325
}
279326

280327
register_diagnostics! {
281-
E0009,
282328
E0010,
283329
E0011,
284330
E0012,

0 commit comments

Comments
 (0)