Skip to content

Commit bd1e778

Browse files
Improve description
1 parent 5c3aad2 commit bd1e778

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

src/librustc/diagnostics.rs

+22-9
Original file line numberDiff line numberDiff line change
@@ -113,37 +113,50 @@ putting the condition inside the body of the arm.
113113
"##,
114114

115115
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.
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+
118121
Wrong example:
122+
123+
```
119124
struct X { x: (), }
120125
121126
let x = Some((X { x: () }, X { x: () }));
122127
match x {
123-
Some((_y, ref _z)) => {},
128+
Some((y, ref z)) => {},
124129
None => panic!()
125130
}
131+
```
126132
127133
You have two solutions:
128-
* implement the Copy trait on the X structure:
129-
#[derive(Clone, Copy)]
134+
1. Bind the pattern's values the same way:
135+
136+
```
130137
struct X { x: (), }
131138
132139
let x = Some((X { x: () }, X { x: () }));
133140
match x {
134-
Some((_y, ref _z)) => {},
141+
Some((ref y, ref z)) => {},
142+
// or Some((y, z)) => {}
135143
None => panic!()
136144
}
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!):
137149
138-
* bind the the pattern's values the same way:
150+
```
151+
#[derive(Clone, Copy)]
139152
struct X { x: (), }
140153
141154
let x = Some((X { x: () }, X { x: () }));
142155
match x {
143-
Some((ref _y, ref _z)) => {},
144-
// or Some((_y, _z)) => {}
156+
Some((y, ref z)) => {},
145157
None => panic!()
146158
}
159+
```
147160
"##,
148161

149162
E0162: r##"

0 commit comments

Comments
 (0)