Skip to content

Commit 9a15234

Browse files
Add long diagnostics for "bind by-ref and by-move"
1 parent ce27d02 commit 9a15234

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

src/librustc/diagnostics.rs

+47-1
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),
@@ -232,7 +279,6 @@ See also https://github.com/rust-lang/rust/issues/14587
232279
}
233280

234281
register_diagnostics! {
235-
E0009,
236282
E0010,
237283
E0011,
238284
E0012,

0 commit comments

Comments
 (0)