Skip to content

Commit 50f75f3

Browse files
GuillaumeGomezmichaelsproul
authored andcommitted
Add long diagnostics for "bind by-ref and by-move"
1 parent 017bc44 commit 50f75f3

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

src/librustc/diagnostics.rs

+48-1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,54 @@ reference when using guards or refactor the entire expression, perhaps by
114114
putting the condition inside the body of the arm.
115115
"##,
116116

117+
E0009: r##"
118+
In a pattern, all values that don't implement the `Copy` trait have to be bound
119+
the same way. The goal here is to avoid binding simultaneously by-move and
120+
by-ref.
121+
122+
This limitation may be removed in a future version of Rust.
123+
124+
Wrong example:
125+
126+
```
127+
struct X { x: (), }
128+
129+
let x = Some((X { x: () }, X { x: () }));
130+
match x {
131+
Some((y, ref z)) => {},
132+
None => panic!()
133+
}
134+
```
135+
136+
You have two solutions:
137+
1. Bind the pattern's values the same way:
138+
139+
```
140+
struct X { x: (), }
141+
142+
let x = Some((X { x: () }, X { x: () }));
143+
match x {
144+
Some((ref y, ref z)) => {},
145+
// or Some((y, z)) => {}
146+
None => panic!()
147+
}
148+
```
149+
150+
2. Implement the `Copy` trait for the X structure (however, please
151+
keep in mind that the first solution should be preferred!):
152+
153+
```
154+
#[derive(Clone, Copy)]
155+
struct X { x: (), }
156+
157+
let x = Some((X { x: () }, X { x: () }));
158+
match x {
159+
Some((y, ref z)) => {},
160+
None => panic!()
161+
}
162+
```
163+
"##,
164+
117165
E0015: r##"
118166
The only function calls allowed in static or constant expressions are enum
119167
variant constructors or struct constructors (for unit or tuple structs). This
@@ -343,7 +391,6 @@ a compile-time constant.
343391
}
344392

345393
register_diagnostics! {
346-
E0009,
347394
E0010,
348395
E0011,
349396
E0012,

0 commit comments

Comments
 (0)