about summary refs log tree commit diff
path: root/tests/ui/pattern
diff options
context:
space:
mode:
authorNadrieril <nadrieril+git@gmail.com>2024-10-06 20:05:27 +0200
committerNadrieril <nadrieril+git@gmail.com>2024-10-07 23:11:06 +0200
commit4abbdfa1c9cd3e2f3181608fb60539755f3a8068 (patch)
tree8767631706e39b8839c9da0bdc0248b7999b5e5d /tests/ui/pattern
parentc22588b700a62a1d93ff7bc30fd49583efab4ad2 (diff)
downloadrust-4abbdfa1c9cd3e2f3181608fb60539755f3a8068.tar.gz
rust-4abbdfa1c9cd3e2f3181608fb60539755f3a8068.zip
Prepare tests
Diffstat (limited to 'tests/ui/pattern')
-rw-r--r--tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.fixed111
-rw-r--r--tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.rs111
-rw-r--r--tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.stderr105
3 files changed, 256 insertions, 71 deletions
diff --git a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.fixed b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.fixed
index 253c9589a55..528d274c0ac 100644
--- a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.fixed
+++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.fixed
@@ -8,49 +8,120 @@
 
 extern crate migration_lint_macros;
 
-struct Foo(u8);
+struct Foo<T>(T);
+
+// Tests type equality in a way that avoids coercing `&&T` to `&T`.
+trait Eq<T> {}
+impl<T> Eq<T> for T {}
+fn assert_type_eq<T, U: Eq<T>>(_: T, _: U) {}
 
 fn main() {
-    let &Foo(mut a) = &Foo(0);
-    //~^ ERROR: the semantics of this pattern will change in edition 2024
-    a = 42;
+    let Foo(x) = &Foo(0);
+    assert_type_eq(x, &0u8);
+
+    let Foo(x) = &mut Foo(0);
+    assert_type_eq(x, &mut 0u8);
 
-    let &mut Foo(mut a) = &mut Foo(0);
+    let &Foo(mut x) = &Foo(0);
     //~^ ERROR: the semantics of this pattern will change in edition 2024
-    a = 42;
+    assert_type_eq(x, 0u8);
 
-    if let &&&&&Some(&_) = &&&&&Some(&0u8) {}
+    let &mut Foo(mut x) = &mut Foo(0);
     //~^ ERROR: the semantics of this pattern will change in edition 2024
+    assert_type_eq(x, 0u8);
+
+    let Foo(ref x) = &Foo(0);
+    assert_type_eq(x, &0u8);
+
+    let Foo(ref x) = &mut Foo(0);
+    assert_type_eq(x, &0u8);
+
+    let &Foo(x) = &Foo(0);
+    assert_type_eq(x, 0u8);
 
-    if let &&&&&Some(&mut _) = &&&&&Some(&mut 0u8) {}
+    let &mut Foo(x) = &mut Foo(0);
+    assert_type_eq(x, 0u8);
+
+    let &Foo(x) = &Foo(&0);
+    assert_type_eq(x, &0u8);
+
+    let &mut Foo(x) = &mut Foo(&0);
+    assert_type_eq(x, &0u8);
+
+    let &Foo(&x) = &Foo(&0);
     //~^ ERROR: the semantics of this pattern will change in edition 2024
+    assert_type_eq(x, 0u8);
 
-    if let &&&&&mut Some(&_) = &&&&&mut Some(&0u8) {}
+    let &Foo(&mut x) = &Foo(&mut 0);
     //~^ ERROR: the semantics of this pattern will change in edition 2024
+    assert_type_eq(x, 0u8);
 
-    if let &mut Some(&mut Some(&mut Some(_))) = &mut Some(&mut Some(&mut Some(0u8))) {}
+    let &mut Foo(&x) = &mut Foo(&0);
     //~^ ERROR: the semantics of this pattern will change in edition 2024
+    assert_type_eq(x, 0u8);
 
-    if let &mut Some(&mut Some(&mut Some(ref mut _a))) = &mut Some(&mut Some(&mut Some(0u8))) {}
+    let &mut Foo(&mut x) = &mut Foo(&mut 0);
     //~^ ERROR: the semantics of this pattern will change in edition 2024
+    assert_type_eq(x, 0u8);
+
+    if let Some(x) = &&&&&Some(&0u8) {
+        assert_type_eq(x, &&0u8);
+    }
+
+    if let &&&&&Some(&x) = &&&&&Some(&0u8) {
+        //~^ ERROR: the semantics of this pattern will change in edition 2024
+        assert_type_eq(x, 0u8);
+    }
+
+    if let &&&&&Some(&mut x) = &&&&&Some(&mut 0u8) {
+        //~^ ERROR: the semantics of this pattern will change in edition 2024
+        assert_type_eq(x, 0u8);
+    }
+
+    if let &&&&&mut Some(&x) = &&&&&mut Some(&0u8) {
+        //~^ ERROR: the semantics of this pattern will change in edition 2024
+        assert_type_eq(x, 0u8);
+    }
+
+    if let &mut Some(&mut Some(&mut Some(ref mut x))) = &mut Some(&mut Some(&mut Some(0u8))) {
+        //~^ ERROR: the semantics of this pattern will change in edition 2024
+        assert_type_eq(x, &mut 0u8);
+    }
 
-    struct Struct {
-        a: u32,
-        b: u32,
-        c: u32,
+    struct Struct<A, B, C> {
+        a: A,
+        b: B,
+        c: C,
     }
-    let s = Struct { a: 0, b: 0, c: 0 };
-    let &Struct { ref a, mut b, ref c } = &s;
+
+    let &Struct { ref a, mut b, ref c } = &Struct { a: 0, b: 0, c: 0 };
+    //~^ ERROR: the semantics of this pattern will change in edition 2024
+    assert_type_eq(a, &0u32);
+    assert_type_eq(b, 0u32);
+
+    let &Struct { a: &a, ref b, ref c } = &Struct { a: &0, b: &0, c: &0 };
     //~^ ERROR: the semantics of this pattern will change in edition 2024
+    assert_type_eq(a, 0u32);
+    assert_type_eq(b, &&0u32);
+    assert_type_eq(c, &&0u32);
+
+    if let &Struct { a: &Some(a), b: &Some(&b), c: &Some(ref c) } =
+        //~^ ERROR: the semantics of this pattern will change in edition 2024
+        &(Struct { a: &Some(&0), b: &Some(&0), c: &Some(&0) })
+    {
+        assert_type_eq(a, &0u32);
+        assert_type_eq(b, 0u32);
+        assert_type_eq(c, &&0u32);
+    }
 
     #[warn(rust_2024_incompatible_pat)]
     match &(Some(0), Some(0)) {
         // The two patterns are the same syntactically, but because they're defined in different
         // editions they don't mean the same thing.
-        (Some(mut _x), migration_lint_macros::mixed_edition_pat!(_y)) => {
+        (Some(mut x), migration_lint_macros::mixed_edition_pat!(y)) => {
             //~^ WARN: the semantics of this pattern will change in edition 2024
-            _x = 4;
-            _y = &7;
+            assert_type_eq(x, 0u32);
+            assert_type_eq(y, &0u32);
         }
         _ => {}
     }
diff --git a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.rs b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.rs
index 1406db779cc..0c5be2c761d 100644
--- a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.rs
+++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.rs
@@ -8,49 +8,120 @@
 
 extern crate migration_lint_macros;
 
-struct Foo(u8);
+struct Foo<T>(T);
+
+// Tests type equality in a way that avoids coercing `&&T` to `&T`.
+trait Eq<T> {}
+impl<T> Eq<T> for T {}
+fn assert_type_eq<T, U: Eq<T>>(_: T, _: U) {}
 
 fn main() {
-    let Foo(mut a) = &Foo(0);
-    //~^ ERROR: the semantics of this pattern will change in edition 2024
-    a = 42;
+    let Foo(x) = &Foo(0);
+    assert_type_eq(x, &0u8);
+
+    let Foo(x) = &mut Foo(0);
+    assert_type_eq(x, &mut 0u8);
 
-    let Foo(mut a) = &mut Foo(0);
+    let Foo(mut x) = &Foo(0);
     //~^ ERROR: the semantics of this pattern will change in edition 2024
-    a = 42;
+    assert_type_eq(x, 0u8);
 
-    if let Some(&_) = &&&&&Some(&0u8) {}
+    let Foo(mut x) = &mut Foo(0);
     //~^ ERROR: the semantics of this pattern will change in edition 2024
+    assert_type_eq(x, 0u8);
+
+    let Foo(ref x) = &Foo(0);
+    assert_type_eq(x, &0u8);
+
+    let Foo(ref x) = &mut Foo(0);
+    assert_type_eq(x, &0u8);
+
+    let &Foo(x) = &Foo(0);
+    assert_type_eq(x, 0u8);
 
-    if let Some(&mut _) = &&&&&Some(&mut 0u8) {}
+    let &mut Foo(x) = &mut Foo(0);
+    assert_type_eq(x, 0u8);
+
+    let &Foo(x) = &Foo(&0);
+    assert_type_eq(x, &0u8);
+
+    let &mut Foo(x) = &mut Foo(&0);
+    assert_type_eq(x, &0u8);
+
+    let Foo(&x) = &Foo(&0);
     //~^ ERROR: the semantics of this pattern will change in edition 2024
+    assert_type_eq(x, 0u8);
 
-    if let Some(&_) = &&&&&mut Some(&0u8) {}
+    let Foo(&mut x) = &Foo(&mut 0);
     //~^ ERROR: the semantics of this pattern will change in edition 2024
+    assert_type_eq(x, 0u8);
 
-    if let Some(&mut Some(Some(_))) = &mut Some(&mut Some(&mut Some(0u8))) {}
+    let Foo(&x) = &mut Foo(&0);
     //~^ ERROR: the semantics of this pattern will change in edition 2024
+    assert_type_eq(x, 0u8);
 
-    if let Some(&mut Some(Some(_a))) = &mut Some(&mut Some(&mut Some(0u8))) {}
+    let Foo(&mut x) = &mut Foo(&mut 0);
     //~^ ERROR: the semantics of this pattern will change in edition 2024
+    assert_type_eq(x, 0u8);
+
+    if let Some(x) = &&&&&Some(&0u8) {
+        assert_type_eq(x, &&0u8);
+    }
+
+    if let Some(&x) = &&&&&Some(&0u8) {
+        //~^ ERROR: the semantics of this pattern will change in edition 2024
+        assert_type_eq(x, 0u8);
+    }
+
+    if let Some(&mut x) = &&&&&Some(&mut 0u8) {
+        //~^ ERROR: the semantics of this pattern will change in edition 2024
+        assert_type_eq(x, 0u8);
+    }
+
+    if let Some(&x) = &&&&&mut Some(&0u8) {
+        //~^ ERROR: the semantics of this pattern will change in edition 2024
+        assert_type_eq(x, 0u8);
+    }
+
+    if let Some(&mut Some(Some(x))) = &mut Some(&mut Some(&mut Some(0u8))) {
+        //~^ ERROR: the semantics of this pattern will change in edition 2024
+        assert_type_eq(x, &mut 0u8);
+    }
 
-    struct Struct {
-        a: u32,
-        b: u32,
-        c: u32,
+    struct Struct<A, B, C> {
+        a: A,
+        b: B,
+        c: C,
     }
-    let s = Struct { a: 0, b: 0, c: 0 };
-    let Struct { a, mut b, c } = &s;
+
+    let Struct { a, mut b, c } = &Struct { a: 0, b: 0, c: 0 };
+    //~^ ERROR: the semantics of this pattern will change in edition 2024
+    assert_type_eq(a, &0u32);
+    assert_type_eq(b, 0u32);
+
+    let Struct { a: &a, b, ref c } = &Struct { a: &0, b: &0, c: &0 };
     //~^ ERROR: the semantics of this pattern will change in edition 2024
+    assert_type_eq(a, 0u32);
+    assert_type_eq(b, &&0u32);
+    assert_type_eq(c, &&0u32);
+
+    if let Struct { a: &Some(a), b: Some(&b), c: Some(c) } =
+        //~^ ERROR: the semantics of this pattern will change in edition 2024
+        &(Struct { a: &Some(&0), b: &Some(&0), c: &Some(&0) })
+    {
+        assert_type_eq(a, &0u32);
+        assert_type_eq(b, 0u32);
+        assert_type_eq(c, &&0u32);
+    }
 
     #[warn(rust_2024_incompatible_pat)]
     match &(Some(0), Some(0)) {
         // The two patterns are the same syntactically, but because they're defined in different
         // editions they don't mean the same thing.
-        (Some(mut _x), migration_lint_macros::mixed_edition_pat!(_y)) => {
+        (Some(mut x), migration_lint_macros::mixed_edition_pat!(y)) => {
             //~^ WARN: the semantics of this pattern will change in edition 2024
-            _x = 4;
-            _y = &7;
+            assert_type_eq(x, 0u32);
+            assert_type_eq(y, &0u32);
         }
         _ => {}
     }
diff --git a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.stderr b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.stderr
index 4d723012024..29e9183acc3 100644
--- a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.stderr
+++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.stderr
@@ -1,7 +1,7 @@
 error: the semantics of this pattern will change in edition 2024
-  --> $DIR/migration_lint.rs:14:9
+  --> $DIR/migration_lint.rs:25:9
    |
-LL |     let Foo(mut a) = &Foo(0);
+LL |     let Foo(mut x) = &Foo(0);
    |         -^^^^^^^^^
    |         |
    |         help: desugar the match ergonomics: `&`
@@ -13,85 +13,128 @@ LL | #![deny(rust_2024_incompatible_pat)]
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 error: the semantics of this pattern will change in edition 2024
-  --> $DIR/migration_lint.rs:18:9
+  --> $DIR/migration_lint.rs:29:9
    |
-LL |     let Foo(mut a) = &mut Foo(0);
+LL |     let Foo(mut x) = &mut Foo(0);
    |         -^^^^^^^^^
    |         |
    |         help: desugar the match ergonomics: `&mut`
 
 error: the semantics of this pattern will change in edition 2024
-  --> $DIR/migration_lint.rs:22:12
+  --> $DIR/migration_lint.rs:51:9
    |
-LL |     if let Some(&_) = &&&&&Some(&0u8) {}
+LL |     let Foo(&x) = &Foo(&0);
+   |         -^^^^^^
+   |         |
+   |         help: desugar the match ergonomics: `&`
+
+error: the semantics of this pattern will change in edition 2024
+  --> $DIR/migration_lint.rs:55:9
+   |
+LL |     let Foo(&mut x) = &Foo(&mut 0);
+   |         -^^^^^^^^^^
+   |         |
+   |         help: desugar the match ergonomics: `&`
+
+error: the semantics of this pattern will change in edition 2024
+  --> $DIR/migration_lint.rs:59:9
+   |
+LL |     let Foo(&x) = &mut Foo(&0);
+   |         -^^^^^^
+   |         |
+   |         help: desugar the match ergonomics: `&mut`
+
+error: the semantics of this pattern will change in edition 2024
+  --> $DIR/migration_lint.rs:63:9
+   |
+LL |     let Foo(&mut x) = &mut Foo(&mut 0);
+   |         -^^^^^^^^^^
+   |         |
+   |         help: desugar the match ergonomics: `&mut`
+
+error: the semantics of this pattern will change in edition 2024
+  --> $DIR/migration_lint.rs:71:12
+   |
+LL |     if let Some(&x) = &&&&&Some(&0u8) {
    |            -^^^^^^^
    |            |
    |            help: desugar the match ergonomics: `&&&&&`
 
 error: the semantics of this pattern will change in edition 2024
-  --> $DIR/migration_lint.rs:25:12
+  --> $DIR/migration_lint.rs:76:12
    |
-LL |     if let Some(&mut _) = &&&&&Some(&mut 0u8) {}
+LL |     if let Some(&mut x) = &&&&&Some(&mut 0u8) {
    |            -^^^^^^^^^^^
    |            |
    |            help: desugar the match ergonomics: `&&&&&`
 
 error: the semantics of this pattern will change in edition 2024
-  --> $DIR/migration_lint.rs:28:12
+  --> $DIR/migration_lint.rs:81:12
    |
-LL |     if let Some(&_) = &&&&&mut Some(&0u8) {}
+LL |     if let Some(&x) = &&&&&mut Some(&0u8) {
    |            -^^^^^^^
    |            |
    |            help: desugar the match ergonomics: `&&&&&mut`
 
 error: the semantics of this pattern will change in edition 2024
-  --> $DIR/migration_lint.rs:31:12
+  --> $DIR/migration_lint.rs:86:12
    |
-LL |     if let Some(&mut Some(Some(_))) = &mut Some(&mut Some(&mut Some(0u8))) {}
+LL |     if let Some(&mut Some(Some(x))) = &mut Some(&mut Some(&mut Some(0u8))) {
    |            ^^^^^^^^^^^^^^^^^^^^^^^^
    |
 help: desugar the match ergonomics
    |
-LL |     if let &mut Some(&mut Some(&mut Some(_))) = &mut Some(&mut Some(&mut Some(0u8))) {}
-   |            ++++                ++++
+LL |     if let &mut Some(&mut Some(&mut Some(ref mut x))) = &mut Some(&mut Some(&mut Some(0u8))) {
+   |            ++++                ++++      +++++++
 
 error: the semantics of this pattern will change in edition 2024
-  --> $DIR/migration_lint.rs:34:12
+  --> $DIR/migration_lint.rs:97:9
    |
-LL |     if let Some(&mut Some(Some(_a))) = &mut Some(&mut Some(&mut Some(0u8))) {}
-   |            ^^^^^^^^^^^^^^^^^^^^^^^^^
+LL |     let Struct { a, mut b, c } = &Struct { a: 0, b: 0, c: 0 };
+   |         ^^^^^^^^^^^^^^^^^^^^^^
    |
 help: desugar the match ergonomics
    |
-LL |     if let &mut Some(&mut Some(&mut Some(ref mut _a))) = &mut Some(&mut Some(&mut Some(0u8))) {}
-   |            ++++                ++++      +++++++
+LL |     let &Struct { ref a, mut b, ref c } = &Struct { a: 0, b: 0, c: 0 };
+   |         +         +++           +++
 
 error: the semantics of this pattern will change in edition 2024
-  --> $DIR/migration_lint.rs:43:9
+  --> $DIR/migration_lint.rs:102:9
    |
-LL |     let Struct { a, mut b, c } = &s;
-   |         ^^^^^^^^^^^^^^^^^^^^^^
+LL |     let Struct { a: &a, b, ref c } = &Struct { a: &0, b: &0, c: &0 };
+   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
 help: desugar the match ergonomics
    |
-LL |     let &Struct { ref a, mut b, ref c } = &s;
-   |         +         +++           +++
+LL |     let &Struct { a: &a, ref b, ref c } = &Struct { a: &0, b: &0, c: &0 };
+   |         +                +++
+
+error: the semantics of this pattern will change in edition 2024
+  --> $DIR/migration_lint.rs:108:12
+   |
+LL |     if let Struct { a: &Some(a), b: Some(&b), c: Some(c) } =
+   |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+help: desugar the match ergonomics
+   |
+LL |     if let &Struct { a: &Some(a), b: &Some(&b), c: &Some(ref c) } =
+   |            +                         +             +     +++
 
 warning: the semantics of this pattern will change in edition 2024
-  --> $DIR/migration_lint.rs:50:9
+  --> $DIR/migration_lint.rs:121:9
    |
-LL |         (Some(mut _x), migration_lint_macros::mixed_edition_pat!(_y)) => {
-   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+LL |         (Some(mut x), migration_lint_macros::mixed_edition_pat!(y)) => {
+   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
 note: the lint level is defined here
-  --> $DIR/migration_lint.rs:46:12
+  --> $DIR/migration_lint.rs:117:12
    |
 LL |     #[warn(rust_2024_incompatible_pat)]
    |            ^^^^^^^^^^^^^^^^^^^^^^^^^^
 help: desugar the match ergonomics
    |
-LL |         &(Some(mut _x), migration_lint_macros::mixed_edition_pat!(ref _y)) => {
-   |         +                                                         +++
+LL |         &(Some(mut x), migration_lint_macros::mixed_edition_pat!(ref y)) => {
+   |         +                                                        +++
 
-error: aborting due to 8 previous errors; 1 warning emitted
+error: aborting due to 13 previous errors; 1 warning emitted