|
8 | 8 |
|
9 | 9 | extern crate migration_lint_macros;
|
10 | 10 |
|
11 |
| -struct Foo(u8); |
| 11 | +struct Foo<T>(T); |
| 12 | + |
| 13 | +// Tests type equality in a way that avoids coercing `&&T` to `&T`. |
| 14 | +trait Eq<T> {} |
| 15 | +impl<T> Eq<T> for T {} |
| 16 | +fn assert_type_eq<T, U: Eq<T>>(_: T, _: U) {} |
12 | 17 |
|
13 | 18 | fn main() {
|
14 |
| - let &Foo(mut a) = &Foo(0); |
15 |
| - //~^ ERROR: the semantics of this pattern will change in edition 2024 |
16 |
| - a = 42; |
| 19 | + let Foo(x) = &Foo(0); |
| 20 | + assert_type_eq(x, &0u8); |
| 21 | + |
| 22 | + let Foo(x) = &mut Foo(0); |
| 23 | + assert_type_eq(x, &mut 0u8); |
17 | 24 |
|
18 |
| - let &mut Foo(mut a) = &mut Foo(0); |
| 25 | + let &Foo(mut x) = &Foo(0); |
19 | 26 | //~^ ERROR: the semantics of this pattern will change in edition 2024
|
20 |
| - a = 42; |
| 27 | + assert_type_eq(x, 0u8); |
21 | 28 |
|
22 |
| - if let &&&&&Some(&_) = &&&&&Some(&0u8) {} |
| 29 | + let &mut Foo(mut x) = &mut Foo(0); |
23 | 30 | //~^ ERROR: the semantics of this pattern will change in edition 2024
|
| 31 | + assert_type_eq(x, 0u8); |
| 32 | + |
| 33 | + let Foo(ref x) = &Foo(0); |
| 34 | + assert_type_eq(x, &0u8); |
| 35 | + |
| 36 | + let Foo(ref x) = &mut Foo(0); |
| 37 | + assert_type_eq(x, &0u8); |
| 38 | + |
| 39 | + let &Foo(x) = &Foo(0); |
| 40 | + assert_type_eq(x, 0u8); |
24 | 41 |
|
25 |
| - if let &&&&&Some(&mut _) = &&&&&Some(&mut 0u8) {} |
| 42 | + let &mut Foo(x) = &mut Foo(0); |
| 43 | + assert_type_eq(x, 0u8); |
| 44 | + |
| 45 | + let &Foo(x) = &Foo(&0); |
| 46 | + assert_type_eq(x, &0u8); |
| 47 | + |
| 48 | + let &mut Foo(x) = &mut Foo(&0); |
| 49 | + assert_type_eq(x, &0u8); |
| 50 | + |
| 51 | + let &Foo(&x) = &Foo(&0); |
26 | 52 | //~^ ERROR: the semantics of this pattern will change in edition 2024
|
| 53 | + assert_type_eq(x, 0u8); |
27 | 54 |
|
28 |
| - if let &&&&&mut Some(&_) = &&&&&mut Some(&0u8) {} |
| 55 | + let &Foo(&mut x) = &Foo(&mut 0); |
29 | 56 | //~^ ERROR: the semantics of this pattern will change in edition 2024
|
| 57 | + assert_type_eq(x, 0u8); |
30 | 58 |
|
31 |
| - if let &mut Some(&mut Some(&mut Some(_))) = &mut Some(&mut Some(&mut Some(0u8))) {} |
| 59 | + let &mut Foo(&x) = &mut Foo(&0); |
32 | 60 | //~^ ERROR: the semantics of this pattern will change in edition 2024
|
| 61 | + assert_type_eq(x, 0u8); |
33 | 62 |
|
34 |
| - if let &mut Some(&mut Some(&mut Some(ref mut _a))) = &mut Some(&mut Some(&mut Some(0u8))) {} |
| 63 | + let &mut Foo(&mut x) = &mut Foo(&mut 0); |
35 | 64 | //~^ ERROR: the semantics of this pattern will change in edition 2024
|
| 65 | + assert_type_eq(x, 0u8); |
| 66 | + |
| 67 | + if let Some(x) = &&&&&Some(&0u8) { |
| 68 | + assert_type_eq(x, &&0u8); |
| 69 | + } |
| 70 | + |
| 71 | + if let &&&&&Some(&x) = &&&&&Some(&0u8) { |
| 72 | + //~^ ERROR: the semantics of this pattern will change in edition 2024 |
| 73 | + assert_type_eq(x, 0u8); |
| 74 | + } |
| 75 | + |
| 76 | + if let &&&&&Some(&mut x) = &&&&&Some(&mut 0u8) { |
| 77 | + //~^ ERROR: the semantics of this pattern will change in edition 2024 |
| 78 | + assert_type_eq(x, 0u8); |
| 79 | + } |
| 80 | + |
| 81 | + if let &&&&&mut Some(&x) = &&&&&mut Some(&0u8) { |
| 82 | + //~^ ERROR: the semantics of this pattern will change in edition 2024 |
| 83 | + assert_type_eq(x, 0u8); |
| 84 | + } |
| 85 | + |
| 86 | + if let &mut Some(&mut Some(&mut Some(ref mut x))) = &mut Some(&mut Some(&mut Some(0u8))) { |
| 87 | + //~^ ERROR: the semantics of this pattern will change in edition 2024 |
| 88 | + assert_type_eq(x, &mut 0u8); |
| 89 | + } |
36 | 90 |
|
37 |
| - struct Struct { |
38 |
| - a: u32, |
39 |
| - b: u32, |
40 |
| - c: u32, |
| 91 | + struct Struct<A, B, C> { |
| 92 | + a: A, |
| 93 | + b: B, |
| 94 | + c: C, |
41 | 95 | }
|
42 |
| - let s = Struct { a: 0, b: 0, c: 0 }; |
43 |
| - let &Struct { ref a, mut b, ref c } = &s; |
| 96 | + |
| 97 | + let &Struct { ref a, mut b, ref c } = &Struct { a: 0, b: 0, c: 0 }; |
| 98 | + //~^ ERROR: the semantics of this pattern will change in edition 2024 |
| 99 | + assert_type_eq(a, &0u32); |
| 100 | + assert_type_eq(b, 0u32); |
| 101 | + |
| 102 | + let &Struct { a: &a, ref b, ref c } = &Struct { a: &0, b: &0, c: &0 }; |
44 | 103 | //~^ ERROR: the semantics of this pattern will change in edition 2024
|
| 104 | + assert_type_eq(a, 0u32); |
| 105 | + assert_type_eq(b, &&0u32); |
| 106 | + assert_type_eq(c, &&0u32); |
| 107 | + |
| 108 | + if let &Struct { a: &Some(a), b: &Some(&b), c: &Some(ref c) } = |
| 109 | + //~^ ERROR: the semantics of this pattern will change in edition 2024 |
| 110 | + &(Struct { a: &Some(&0), b: &Some(&0), c: &Some(&0) }) |
| 111 | + { |
| 112 | + assert_type_eq(a, &0u32); |
| 113 | + assert_type_eq(b, 0u32); |
| 114 | + assert_type_eq(c, &&0u32); |
| 115 | + } |
45 | 116 |
|
46 | 117 | #[warn(rust_2024_incompatible_pat)]
|
47 | 118 | match &(Some(0), Some(0)) {
|
48 | 119 | // The two patterns are the same syntactically, but because they're defined in different
|
49 | 120 | // editions they don't mean the same thing.
|
50 |
| - (Some(mut _x), migration_lint_macros::mixed_edition_pat!(_y)) => { |
| 121 | + (Some(mut x), migration_lint_macros::mixed_edition_pat!(y)) => { |
51 | 122 | //~^ WARN: the semantics of this pattern will change in edition 2024
|
52 |
| - _x = 4; |
53 |
| - _y = &7; |
| 123 | + assert_type_eq(x, 0u32); |
| 124 | + assert_type_eq(y, &0u32); |
54 | 125 | }
|
55 | 126 | _ => {}
|
56 | 127 | }
|
|
0 commit comments