Skip to content

Commit 5c3aad2

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

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

src/librustc/diagnostics.rs

+34-1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,40 @@ 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 binded the same way
117+
than the others. The goal here is to avoid to bind by-move and by-ref at the same time.
118+
Wrong example:
119+
struct X { x: (), }
120+
121+
let x = Some((X { x: () }, X { x: () }));
122+
match x {
123+
Some((_y, ref _z)) => {},
124+
None => panic!()
125+
}
126+
127+
You have two solutions:
128+
* implement the Copy trait on the X structure:
129+
#[derive(Clone, Copy)]
130+
struct X { x: (), }
131+
132+
let x = Some((X { x: () }, X { x: () }));
133+
match x {
134+
Some((_y, ref _z)) => {},
135+
None => panic!()
136+
}
137+
138+
* bind the the pattern's values the same way:
139+
struct X { x: (), }
140+
141+
let x = Some((X { x: () }, X { x: () }));
142+
match x {
143+
Some((ref _y, ref _z)) => {},
144+
// or Some((_y, _z)) => {}
145+
None => panic!()
146+
}
147+
"##,
148+
115149
E0162: r##"
116150
An if-let pattern attempts to match the pattern, and enters the body if the
117151
match was succesful. If the match is irrefutable (when it cannot fail to match),
@@ -232,7 +266,6 @@ See also https://github.com/rust-lang/rust/issues/14587
232266
}
233267

234268
register_diagnostics! {
235-
E0009,
236269
E0010,
237270
E0011,
238271
E0012,

0 commit comments

Comments
 (0)