Skip to content

Commit cf53f03

Browse files
Add long diagnostics for "bind by-ref and by-move"
1 parent b7fb575 commit cf53f03

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
E0152: r##"
116163
Lang items are already implemented in the standard library. Unless you are
117164
writing a free-standing application (e.g. a kernel), you do not need to provide
@@ -308,7 +355,6 @@ a compile-time constant.
308355
}
309356

310357
register_diagnostics! {
311-
E0009,
312358
E0010,
313359
E0011,
314360
E0012,

0 commit comments

Comments
 (0)