Skip to content

Commit 4abbdfa

Browse files
committed
Prepare tests
1 parent c22588b commit 4abbdfa

File tree

3 files changed

+256
-71
lines changed

3 files changed

+256
-71
lines changed

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

Lines changed: 91 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,49 +8,120 @@
88

99
extern crate migration_lint_macros;
1010

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) {}
1217

1318
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);
1724

18-
let &mut Foo(mut a) = &mut Foo(0);
25+
let &Foo(mut x) = &Foo(0);
1926
//~^ ERROR: the semantics of this pattern will change in edition 2024
20-
a = 42;
27+
assert_type_eq(x, 0u8);
2128

22-
if let &&&&&Some(&_) = &&&&&Some(&0u8) {}
29+
let &mut Foo(mut x) = &mut Foo(0);
2330
//~^ 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);
2441

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);
2652
//~^ ERROR: the semantics of this pattern will change in edition 2024
53+
assert_type_eq(x, 0u8);
2754

28-
if let &&&&&mut Some(&_) = &&&&&mut Some(&0u8) {}
55+
let &Foo(&mut x) = &Foo(&mut 0);
2956
//~^ ERROR: the semantics of this pattern will change in edition 2024
57+
assert_type_eq(x, 0u8);
3058

31-
if let &mut Some(&mut Some(&mut Some(_))) = &mut Some(&mut Some(&mut Some(0u8))) {}
59+
let &mut Foo(&x) = &mut Foo(&0);
3260
//~^ ERROR: the semantics of this pattern will change in edition 2024
61+
assert_type_eq(x, 0u8);
3362

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);
3564
//~^ 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+
}
3690

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,
4195
}
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 };
44103
//~^ 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+
}
45116

46117
#[warn(rust_2024_incompatible_pat)]
47118
match &(Some(0), Some(0)) {
48119
// The two patterns are the same syntactically, but because they're defined in different
49120
// 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)) => {
51122
//~^ 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);
54125
}
55126
_ => {}
56127
}

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

Lines changed: 91 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,49 +8,120 @@
88

99
extern crate migration_lint_macros;
1010

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) {}
1217

1318
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);
1724

18-
let Foo(mut a) = &mut Foo(0);
25+
let Foo(mut x) = &Foo(0);
1926
//~^ ERROR: the semantics of this pattern will change in edition 2024
20-
a = 42;
27+
assert_type_eq(x, 0u8);
2128

22-
if let Some(&_) = &&&&&Some(&0u8) {}
29+
let Foo(mut x) = &mut Foo(0);
2330
//~^ 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);
2441

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);
2652
//~^ ERROR: the semantics of this pattern will change in edition 2024
53+
assert_type_eq(x, 0u8);
2754

28-
if let Some(&_) = &&&&&mut Some(&0u8) {}
55+
let Foo(&mut x) = &Foo(&mut 0);
2956
//~^ ERROR: the semantics of this pattern will change in edition 2024
57+
assert_type_eq(x, 0u8);
3058

31-
if let Some(&mut Some(Some(_))) = &mut Some(&mut Some(&mut Some(0u8))) {}
59+
let Foo(&x) = &mut Foo(&0);
3260
//~^ ERROR: the semantics of this pattern will change in edition 2024
61+
assert_type_eq(x, 0u8);
3362

34-
if let Some(&mut Some(Some(_a))) = &mut Some(&mut Some(&mut Some(0u8))) {}
63+
let Foo(&mut x) = &mut Foo(&mut 0);
3564
//~^ 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 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 Some(&mut Some(Some(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+
}
3690

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,
4195
}
42-
let s = Struct { a: 0, b: 0, c: 0 };
43-
let Struct { a, mut b, c } = &s;
96+
97+
let Struct { a, mut b, 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, b, ref c } = &Struct { a: &0, b: &0, c: &0 };
44103
//~^ 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(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+
}
45116

46117
#[warn(rust_2024_incompatible_pat)]
47118
match &(Some(0), Some(0)) {
48119
// The two patterns are the same syntactically, but because they're defined in different
49120
// 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)) => {
51122
//~^ 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);
54125
}
55126
_ => {}
56127
}

0 commit comments

Comments
 (0)