Skip to content

Commit cb725bd

Browse files
committed
add targeted pattern migration tests
These are meant to test the changes in the following commits.
1 parent 396ebaa commit cb725bd

File tree

3 files changed

+330
-1
lines changed

3 files changed

+330
-1
lines changed

tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.fixed

+87
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,91 @@ fn main() {
141141
}
142142
_ => {}
143143
}
144+
145+
// Test removing multiple binding modifiers.
146+
let &Struct { ref a, ref b, ref c } = &Struct { a: 0, b: 0, c: 0 };
147+
//~^ ERROR: this pattern relies on behavior which may change in edition 2024
148+
//~| WARN: this changes meaning in Rust 2024
149+
assert_type_eq(a, &0u32);
150+
assert_type_eq(c, &0u32);
151+
152+
// Test that we don't change bindings' modes when removing binding modifiers.
153+
let &mut Struct { ref a, ref mut b, ref mut c } = &mut Struct { a: 0, b: 0, c: 0 };
154+
//~^ ERROR: this pattern relies on behavior which may change in edition 2024
155+
//~| WARN: this changes meaning in Rust 2024
156+
assert_type_eq(a, &0u32);
157+
assert_type_eq(b, &mut 0u32);
158+
assert_type_eq(c, &mut 0u32);
159+
160+
// Test removing multiple reference patterns of various mutabilities, plus a binding modifier.
161+
let &mut &Struct { a: &[ref a], b: &mut [&[ref b]], ref c } = &mut &Struct { a: &[0], b: &mut [&[0]], c: 0 };
162+
//~^ ERROR: this pattern relies on behavior which may change in edition 2024
163+
//~| WARN: this changes meaning in Rust 2024
164+
assert_type_eq(a, &0u32);
165+
assert_type_eq(b, &0u32);
166+
assert_type_eq(c, &0u32);
167+
168+
// Test that we don't change bindings' types when removing reference patterns.
169+
let &Foo(&ref a) = &Foo(&0);
170+
//~^ ERROR: this pattern relies on behavior which may change in edition 2024
171+
//~| WARN: this changes meaning in Rust 2024
172+
assert_type_eq(a, &0u32);
173+
174+
// Test that we don't change bindings' modes when adding reference paterns (caught early).
175+
let &(&a, ref b, &[ref c], &mut [&mut (ref d, &[ref e])]) = &(&0, 0, &[0], &mut [&mut (0, &[0])]);
176+
//~^ ERROR: this pattern relies on behavior which may change in edition 2024
177+
//~| WARN: this changes meaning in Rust 2024
178+
assert_type_eq(a, 0u32);
179+
assert_type_eq(b, &0u32);
180+
assert_type_eq(c, &0u32);
181+
assert_type_eq(d, &0u32);
182+
assert_type_eq(e, &0u32);
183+
184+
// Test that we don't change bindings' modes when adding reference patterns (caught late).
185+
let &(ref a, &mut [ref b], &[mut c]) = &(0, &mut [0], &[0]);
186+
//~^ ERROR: this pattern relies on behavior which may change in edition 2024
187+
//~| WARN: this changes meaning in Rust 2024
188+
assert_type_eq(a, &0u32);
189+
assert_type_eq(b, &0u32);
190+
assert_type_eq(c, 0u32);
191+
192+
// Test featuring both additions and removals.
193+
let &(&a, &mut (ref b, &[ref c])) = &(&0, &mut (0, &[0]));
194+
//~^ ERROR: this pattern relies on behavior which may change in edition 2024
195+
//~| WARN: this changes meaning in Rust 2024
196+
assert_type_eq(a, 0u32);
197+
assert_type_eq(b, &0u32);
198+
assert_type_eq(c, &0u32);
199+
200+
// Test that bindings' subpatterns' modes are updated properly.
201+
let &[mut a @ ref b] = &[0];
202+
//~^ ERROR: this pattern relies on behavior which may change in edition 2024
203+
//~| WARN: this changes meaning in Rust 2024
204+
assert_type_eq(a, 0u32);
205+
assert_type_eq(b, &0u32);
206+
207+
// Test that bindings' subpatterns' modes are checked properly.
208+
let &[ref a @ mut b] = &[0];
209+
//~^ ERROR: this pattern relies on behavior which may change in edition 2024
210+
//~| WARN: this changes meaning in Rust 2024
211+
assert_type_eq(a, &0u32);
212+
assert_type_eq(b, 0u32);
213+
214+
// Test that we respect bindings' subpatterns' types when rewriting `&ref x` to `x`.
215+
let [&Foo(&ref a @ ref b), &Foo(&ref c @ d)] = [&Foo(&0); 2];
216+
//~^ ERROR: this pattern relies on behavior which may change in edition 2024
217+
//~| WARN: this changes meaning in Rust 2024
218+
assert_type_eq(a, &0u32);
219+
assert_type_eq(b, &0u32);
220+
assert_type_eq(c, &0u32);
221+
assert_type_eq(d, 0u32);
222+
223+
// Test that we respect bindings' subpatterns' modes when rewriting `&ref x` to `x`.
224+
let [&Foo(&ref a @ [ref b]), &Foo(&ref c @ [d])] = [&Foo(&[0]); 2];
225+
//~^ ERROR: this pattern relies on behavior which may change in edition 2024
226+
//~| WARN: this changes meaning in Rust 2024
227+
assert_type_eq(a, &[0u32]);
228+
assert_type_eq(b, &0u32);
229+
assert_type_eq(c, &[0u32]);
230+
assert_type_eq(d, 0u32);
144231
}

tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.rs

+87
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,91 @@ fn main() {
141141
}
142142
_ => {}
143143
}
144+
145+
// Test removing multiple binding modifiers.
146+
let Struct { ref a, ref b, c } = &Struct { a: 0, b: 0, c: 0 };
147+
//~^ ERROR: this pattern relies on behavior which may change in edition 2024
148+
//~| WARN: this changes meaning in Rust 2024
149+
assert_type_eq(a, &0u32);
150+
assert_type_eq(c, &0u32);
151+
152+
// Test that we don't change bindings' modes when removing binding modifiers.
153+
let Struct { ref a, ref mut b, c } = &mut Struct { a: 0, b: 0, c: 0 };
154+
//~^ ERROR: this pattern relies on behavior which may change in edition 2024
155+
//~| WARN: this changes meaning in Rust 2024
156+
assert_type_eq(a, &0u32);
157+
assert_type_eq(b, &mut 0u32);
158+
assert_type_eq(c, &mut 0u32);
159+
160+
// Test removing multiple reference patterns of various mutabilities, plus a binding modifier.
161+
let Struct { a: &[ref a], b: &mut [[b]], c } = &mut &Struct { a: &[0], b: &mut [&[0]], c: 0 };
162+
//~^ ERROR: this pattern relies on behavior which may change in edition 2024
163+
//~| WARN: this changes meaning in Rust 2024
164+
assert_type_eq(a, &0u32);
165+
assert_type_eq(b, &0u32);
166+
assert_type_eq(c, &0u32);
167+
168+
// Test that we don't change bindings' types when removing reference patterns.
169+
let Foo(&ref a) = &Foo(&0);
170+
//~^ ERROR: this pattern relies on behavior which may change in edition 2024
171+
//~| WARN: this changes meaning in Rust 2024
172+
assert_type_eq(a, &0u32);
173+
174+
// Test that we don't change bindings' modes when adding reference paterns (caught early).
175+
let (&a, b, [c], [(d, [e])]) = &(&0, 0, &[0], &mut [&mut (0, &[0])]);
176+
//~^ ERROR: this pattern relies on behavior which may change in edition 2024
177+
//~| WARN: this changes meaning in Rust 2024
178+
assert_type_eq(a, 0u32);
179+
assert_type_eq(b, &0u32);
180+
assert_type_eq(c, &0u32);
181+
assert_type_eq(d, &0u32);
182+
assert_type_eq(e, &0u32);
183+
184+
// Test that we don't change bindings' modes when adding reference patterns (caught late).
185+
let (a, [b], [mut c]) = &(0, &mut [0], &[0]);
186+
//~^ ERROR: this pattern relies on behavior which may change in edition 2024
187+
//~| WARN: this changes meaning in Rust 2024
188+
assert_type_eq(a, &0u32);
189+
assert_type_eq(b, &0u32);
190+
assert_type_eq(c, 0u32);
191+
192+
// Test featuring both additions and removals.
193+
let (&a, (b, &[ref c])) = &(&0, &mut (0, &[0]));
194+
//~^ ERROR: this pattern relies on behavior which may change in edition 2024
195+
//~| WARN: this changes meaning in Rust 2024
196+
assert_type_eq(a, 0u32);
197+
assert_type_eq(b, &0u32);
198+
assert_type_eq(c, &0u32);
199+
200+
// Test that bindings' subpatterns' modes are updated properly.
201+
let [mut a @ b] = &[0];
202+
//~^ ERROR: this pattern relies on behavior which may change in edition 2024
203+
//~| WARN: this changes meaning in Rust 2024
204+
assert_type_eq(a, 0u32);
205+
assert_type_eq(b, &0u32);
206+
207+
// Test that bindings' subpatterns' modes are checked properly.
208+
let [a @ mut b] = &[0];
209+
//~^ ERROR: this pattern relies on behavior which may change in edition 2024
210+
//~| WARN: this changes meaning in Rust 2024
211+
assert_type_eq(a, &0u32);
212+
assert_type_eq(b, 0u32);
213+
214+
// Test that we respect bindings' subpatterns' types when rewriting `&ref x` to `x`.
215+
let [Foo(&ref a @ ref b), Foo(&ref c @ d)] = [&Foo(&0); 2];
216+
//~^ ERROR: this pattern relies on behavior which may change in edition 2024
217+
//~| WARN: this changes meaning in Rust 2024
218+
assert_type_eq(a, &0u32);
219+
assert_type_eq(b, &0u32);
220+
assert_type_eq(c, &0u32);
221+
assert_type_eq(d, 0u32);
222+
223+
// Test that we respect bindings' subpatterns' modes when rewriting `&ref x` to `x`.
224+
let [Foo(&ref a @ [ref b]), Foo(&ref c @ [d])] = [&Foo(&[0]); 2];
225+
//~^ ERROR: this pattern relies on behavior which may change in edition 2024
226+
//~| WARN: this changes meaning in Rust 2024
227+
assert_type_eq(a, &[0u32]);
228+
assert_type_eq(b, &0u32);
229+
assert_type_eq(c, &[0u32]);
230+
assert_type_eq(d, 0u32);
144231
}

tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.stderr

+156-1
Original file line numberDiff line numberDiff line change
@@ -217,5 +217,160 @@ help: make the implied reference pattern explicit
217217
LL | &(Some(mut x), migration_lint_macros::mixed_edition_pat!(y)) => {
218218
| +
219219

220-
error: aborting due to 16 previous errors
220+
error: this pattern relies on behavior which may change in edition 2024
221+
--> $DIR/migration_lint.rs:146:18
222+
|
223+
LL | let Struct { ref a, ref b, c } = &Struct { a: 0, b: 0, c: 0 };
224+
| ^^^ ^^^ cannot override to bind by-reference when that is the implicit default
225+
| |
226+
| cannot override to bind by-reference when that is the implicit default
227+
|
228+
= warning: this changes meaning in Rust 2024
229+
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
230+
help: make the implied reference pattern and variable binding mode explicit
231+
|
232+
LL | let &Struct { ref a, ref b, ref c } = &Struct { a: 0, b: 0, c: 0 };
233+
| + +++
234+
235+
error: this pattern relies on behavior which may change in edition 2024
236+
--> $DIR/migration_lint.rs:153:18
237+
|
238+
LL | let Struct { ref a, ref mut b, c } = &mut Struct { a: 0, b: 0, c: 0 };
239+
| ^^^ ^^^^^^^ cannot override to bind by-reference when that is the implicit default
240+
| |
241+
| cannot override to bind by-reference when that is the implicit default
242+
|
243+
= warning: this changes meaning in Rust 2024
244+
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
245+
help: make the implied reference pattern and variable binding mode explicit
246+
|
247+
LL | let &mut Struct { ref a, ref mut b, ref mut c } = &mut Struct { a: 0, b: 0, c: 0 };
248+
| ++++ +++++++
249+
250+
error: this pattern relies on behavior which may change in edition 2024
251+
--> $DIR/migration_lint.rs:161:21
252+
|
253+
LL | let Struct { a: &[ref a], b: &mut [[b]], c } = &mut &Struct { a: &[0], b: &mut [&[0]], c: 0 };
254+
| ^ ^^^^ cannot implicitly match against multiple layers of reference
255+
| |
256+
| cannot implicitly match against multiple layers of reference
257+
|
258+
= warning: this changes meaning in Rust 2024
259+
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
260+
help: make the implied reference patterns and variable binding modes explicit
261+
|
262+
LL | let &mut &Struct { a: &[ref a], b: &mut [&[ref b]], ref c } = &mut &Struct { a: &[0], b: &mut [&[0]], c: 0 };
263+
| ++++++ + +++ +++
264+
265+
error: this pattern relies on behavior which may change in edition 2024
266+
--> $DIR/migration_lint.rs:169:13
267+
|
268+
LL | let Foo(&ref a) = &Foo(&0);
269+
| ^ cannot implicitly match against multiple layers of reference
270+
|
271+
= warning: this changes meaning in Rust 2024
272+
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
273+
help: make the implied reference pattern explicit
274+
|
275+
LL | let &Foo(&ref a) = &Foo(&0);
276+
| +
277+
278+
error: this pattern relies on behavior which may change in edition 2024
279+
--> $DIR/migration_lint.rs:175:10
280+
|
281+
LL | let (&a, b, [c], [(d, [e])]) = &(&0, 0, &[0], &mut [&mut (0, &[0])]);
282+
| ^ cannot implicitly match against multiple layers of reference
283+
|
284+
= warning: this changes meaning in Rust 2024
285+
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
286+
help: make the implied reference patterns and variable binding modes explicit
287+
|
288+
LL | let &(&a, ref b, &[ref c], &mut [&mut (ref d, &[ref e])]) = &(&0, 0, &[0], &mut [&mut (0, &[0])]);
289+
| + +++ + +++ ++++ ++++ +++ + +++
290+
291+
error: this pattern relies on behavior which may change in edition 2024
292+
--> $DIR/migration_lint.rs:185:19
293+
|
294+
LL | let (a, [b], [mut c]) = &(0, &mut [0], &[0]);
295+
| ^^^ requires binding by-value, but the implicit default is by-reference
296+
|
297+
= warning: this changes meaning in Rust 2024
298+
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
299+
help: make the implied reference patterns and variable binding modes explicit
300+
|
301+
LL | let &(ref a, &mut [ref b], &[mut c]) = &(0, &mut [0], &[0]);
302+
| + +++ ++++ +++ +
303+
304+
error: this pattern relies on behavior which may change in edition 2024
305+
--> $DIR/migration_lint.rs:193:10
306+
|
307+
LL | let (&a, (b, &[ref c])) = &(&0, &mut (0, &[0]));
308+
| ^ ^ cannot implicitly match against multiple layers of reference
309+
| |
310+
| cannot implicitly match against multiple layers of reference
311+
|
312+
= warning: this changes meaning in Rust 2024
313+
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
314+
help: make the implied reference patterns and variable binding mode explicit
315+
|
316+
LL | let &(&a, &mut (ref b, &[ref c])) = &(&0, &mut (0, &[0]));
317+
| + ++++ +++
318+
319+
error: this pattern relies on behavior which may change in edition 2024
320+
--> $DIR/migration_lint.rs:201:10
321+
|
322+
LL | let [mut a @ b] = &[0];
323+
| ^^^ requires binding by-value, but the implicit default is by-reference
324+
|
325+
= warning: this changes meaning in Rust 2024
326+
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
327+
help: make the implied reference pattern and variable binding mode explicit
328+
|
329+
LL | let &[mut a @ ref b] = &[0];
330+
| + +++
331+
332+
error: this pattern relies on behavior which may change in edition 2024
333+
--> $DIR/migration_lint.rs:208:14
334+
|
335+
LL | let [a @ mut b] = &[0];
336+
| ^^^ requires binding by-value, but the implicit default is by-reference
337+
|
338+
= warning: this changes meaning in Rust 2024
339+
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
340+
help: make the implied reference pattern and variable binding mode explicit
341+
|
342+
LL | let &[ref a @ mut b] = &[0];
343+
| + +++
344+
345+
error: this pattern relies on behavior which may change in edition 2024
346+
--> $DIR/migration_lint.rs:215:14
347+
|
348+
LL | let [Foo(&ref a @ ref b), Foo(&ref c @ d)] = [&Foo(&0); 2];
349+
| ^ ^ cannot implicitly match against multiple layers of reference
350+
| |
351+
| cannot implicitly match against multiple layers of reference
352+
|
353+
= warning: this changes meaning in Rust 2024
354+
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
355+
help: make the implied reference patterns explicit
356+
|
357+
LL | let [&Foo(&ref a @ ref b), &Foo(&ref c @ d)] = [&Foo(&0); 2];
358+
| + +
359+
360+
error: this pattern relies on behavior which may change in edition 2024
361+
--> $DIR/migration_lint.rs:224:14
362+
|
363+
LL | let [Foo(&ref a @ [ref b]), Foo(&ref c @ [d])] = [&Foo(&[0]); 2];
364+
| ^ ^ cannot implicitly match against multiple layers of reference
365+
| |
366+
| cannot implicitly match against multiple layers of reference
367+
|
368+
= warning: this changes meaning in Rust 2024
369+
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
370+
help: make the implied reference patterns explicit
371+
|
372+
LL | let [&Foo(&ref a @ [ref b]), &Foo(&ref c @ [d])] = [&Foo(&[0]); 2];
373+
| + +
374+
375+
error: aborting due to 27 previous errors
221376

0 commit comments

Comments
 (0)