@@ -113,37 +113,50 @@ putting the condition inside the body of the arm.
113
113
"## ,
114
114
115
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.
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
+
118
121
Wrong example:
122
+
123
+ ```
119
124
struct X { x: (), }
120
125
121
126
let x = Some((X { x: () }, X { x: () }));
122
127
match x {
123
- Some((_y , ref _z )) => {},
128
+ Some((y , ref z )) => {},
124
129
None => panic!()
125
130
}
131
+ ```
126
132
127
133
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
+ ```
130
137
struct X { x: (), }
131
138
132
139
let x = Some((X { x: () }, X { x: () }));
133
140
match x {
134
- Some((_y, ref _z)) => {},
141
+ Some((ref y, ref z)) => {},
142
+ // or Some((y, z)) => {}
135
143
None => panic!()
136
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!):
137
149
138
- * bind the the pattern's values the same way:
150
+ ```
151
+ #[derive(Clone, Copy)]
139
152
struct X { x: (), }
140
153
141
154
let x = Some((X { x: () }, X { x: () }));
142
155
match x {
143
- Some((ref _y, ref _z)) => {},
144
- // or Some((_y, _z)) => {}
156
+ Some((y, ref z)) => {},
145
157
None => panic!()
146
158
}
159
+ ```
147
160
"## ,
148
161
149
162
E0162 : r##"
0 commit comments