about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-05-12 19:58:50 +0000
committerbors <bors@rust-lang.org>2024-05-12 19:58:50 +0000
commitef0027897d2e9014766fb47dce9ddbb925d2f540 (patch)
tree971f7ab3c94eb9eb9220eec82c280ab813058800 /tests
parent852a78ea8de3aa24c50457340d9560547bc67008 (diff)
parent9d92a7f35524ad9f55f519da970737cce2613e9f (diff)
downloadrust-ef0027897d2e9014766fb47dce9ddbb925d2f540.tar.gz
rust-ef0027897d2e9014766fb47dce9ddbb925d2f540.zip
Auto merge of #124639 - Jules-Bertholet:match-ergonomics-2024-migration-lint, r=Nadrieril
Match ergonomics 2024: migration lint

Depends on #124567

r? `@Nadrieril`

cc https://github.com/rust-lang/rust/issues/123076

`@rustbot` label A-edition-2024 A-patterns
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/pattern/auxiliary/match_ergonomics_2024_macros.rs12
-rw-r--r--tests/ui/pattern/match_ergonomics_2024.fixed57
-rw-r--r--tests/ui/pattern/match_ergonomics_2024.rs57
-rw-r--r--tests/ui/pattern/match_ergonomics_2024.stderr97
-rw-r--r--tests/ui/pattern/mut_preserve_binding_mode_2024_lint.rs16
-rw-r--r--tests/ui/pattern/mut_preserve_binding_mode_2024_lint.stderr31
6 files changed, 223 insertions, 47 deletions
diff --git a/tests/ui/pattern/auxiliary/match_ergonomics_2024_macros.rs b/tests/ui/pattern/auxiliary/match_ergonomics_2024_macros.rs
new file mode 100644
index 00000000000..0b70e4404ab
--- /dev/null
+++ b/tests/ui/pattern/auxiliary/match_ergonomics_2024_macros.rs
@@ -0,0 +1,12 @@
+//@ edition: 2024
+//@ compile-flags: -Z unstable-options
+
+// This contains a binding in edition 2024, so if matched with a reference binding mode it will end
+// up with a `mut ref mut` binding mode. We use this to test the migration lint on patterns with
+// mixed editions.
+#[macro_export]
+macro_rules! mixed_edition_pat {
+    ($foo:ident) => {
+        Some(mut $foo)
+    };
+}
diff --git a/tests/ui/pattern/match_ergonomics_2024.fixed b/tests/ui/pattern/match_ergonomics_2024.fixed
new file mode 100644
index 00000000000..d8dbcb217c0
--- /dev/null
+++ b/tests/ui/pattern/match_ergonomics_2024.fixed
@@ -0,0 +1,57 @@
+//@ edition: 2021
+//@ run-rustfix
+//@ rustfix-only-machine-applicable
+//@ aux-build:match_ergonomics_2024_macros.rs
+#![feature(mut_preserve_binding_mode_2024, ref_pat_eat_one_layer_2024)]
+#![allow(incomplete_features, unused)]
+#![deny(rust_2024_incompatible_pat)]
+
+extern crate match_ergonomics_2024_macros;
+
+struct Foo(u8);
+
+fn main() {
+    let &Foo(mut a) = &Foo(0);
+    //~^ ERROR: the semantics of this pattern will change in edition 2024
+    a = 42;
+
+    let &mut Foo(mut a) = &mut Foo(0);
+    //~^ ERROR: the semantics of this pattern will change in edition 2024
+    a = 42;
+
+    if let &&&&&Some(&_) = &&&&&Some(&0u8) {}
+    //~^ ERROR: the semantics of this pattern will change in edition 2024
+
+    if let &&&&&Some(&mut _) = &&&&&Some(&mut 0u8) {}
+    //~^ ERROR: the semantics of this pattern will change in edition 2024
+
+    if let &&&&&mut Some(&_) = &&&&&mut Some(&0u8) {}
+    //~^ ERROR: the semantics of this pattern will change in edition 2024
+
+    if let &mut Some(&mut Some(&mut Some(_))) = &mut Some(&mut Some(&mut Some(0u8))) {}
+    //~^ ERROR: the semantics of this pattern will change in edition 2024
+
+    if let &mut Some(&mut Some(&mut Some(ref mut _a))) = &mut Some(&mut Some(&mut Some(0u8))) {}
+    //~^ ERROR: the semantics of this pattern will change in edition 2024
+
+    struct Struct {
+        a: u32,
+        b: u32,
+        c: u32,
+    }
+    let s = Struct { a: 0, b: 0, c: 0 };
+    let &Struct { ref a, mut b, ref c } = &s;
+    //~^ ERROR: the semantics of this pattern will change in edition 2024
+
+    #[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), match_ergonomics_2024_macros::mixed_edition_pat!(_y)) => {
+            //~^ WARN: the semantics of this pattern will change in edition 2024
+            _x = 4;
+            _y = &7;
+        }
+        _ => {}
+    }
+}
diff --git a/tests/ui/pattern/match_ergonomics_2024.rs b/tests/ui/pattern/match_ergonomics_2024.rs
new file mode 100644
index 00000000000..38dc0c8bebb
--- /dev/null
+++ b/tests/ui/pattern/match_ergonomics_2024.rs
@@ -0,0 +1,57 @@
+//@ edition: 2021
+//@ run-rustfix
+//@ rustfix-only-machine-applicable
+//@ aux-build:match_ergonomics_2024_macros.rs
+#![feature(mut_preserve_binding_mode_2024, ref_pat_eat_one_layer_2024)]
+#![allow(incomplete_features, unused)]
+#![deny(rust_2024_incompatible_pat)]
+
+extern crate match_ergonomics_2024_macros;
+
+struct Foo(u8);
+
+fn main() {
+    let Foo(mut a) = &Foo(0);
+    //~^ ERROR: the semantics of this pattern will change in edition 2024
+    a = 42;
+
+    let Foo(mut a) = &mut Foo(0);
+    //~^ ERROR: the semantics of this pattern will change in edition 2024
+    a = 42;
+
+    if let Some(&_) = &&&&&Some(&0u8) {}
+    //~^ ERROR: the semantics of this pattern will change in edition 2024
+
+    if let Some(&mut _) = &&&&&Some(&mut 0u8) {}
+    //~^ ERROR: the semantics of this pattern will change in edition 2024
+
+    if let Some(&_) = &&&&&mut Some(&0u8) {}
+    //~^ ERROR: the semantics of this pattern will change in edition 2024
+
+    if let Some(&mut Some(Some(_))) = &mut Some(&mut Some(&mut Some(0u8))) {}
+    //~^ ERROR: the semantics of this pattern will change in edition 2024
+
+    if let Some(&mut Some(Some(_a))) = &mut Some(&mut Some(&mut Some(0u8))) {}
+    //~^ ERROR: the semantics of this pattern will change in edition 2024
+
+    struct Struct {
+        a: u32,
+        b: u32,
+        c: u32,
+    }
+    let s = Struct { a: 0, b: 0, c: 0 };
+    let Struct { a, mut b, c } = &s;
+    //~^ ERROR: the semantics of this pattern will change in edition 2024
+
+    #[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), match_ergonomics_2024_macros::mixed_edition_pat!(_y)) => {
+            //~^ WARN: the semantics of this pattern will change in edition 2024
+            _x = 4;
+            _y = &7;
+        }
+        _ => {}
+    }
+}
diff --git a/tests/ui/pattern/match_ergonomics_2024.stderr b/tests/ui/pattern/match_ergonomics_2024.stderr
new file mode 100644
index 00000000000..11844434ad2
--- /dev/null
+++ b/tests/ui/pattern/match_ergonomics_2024.stderr
@@ -0,0 +1,97 @@
+error: the semantics of this pattern will change in edition 2024
+  --> $DIR/match_ergonomics_2024.rs:14:9
+   |
+LL |     let Foo(mut a) = &Foo(0);
+   |         -^^^^^^^^^
+   |         |
+   |         help: desugar the match ergonomics: `&`
+   |
+note: the lint level is defined here
+  --> $DIR/match_ergonomics_2024.rs:7:9
+   |
+LL | #![deny(rust_2024_incompatible_pat)]
+   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: the semantics of this pattern will change in edition 2024
+  --> $DIR/match_ergonomics_2024.rs:18:9
+   |
+LL |     let Foo(mut a) = &mut Foo(0);
+   |         -^^^^^^^^^
+   |         |
+   |         help: desugar the match ergonomics: `&mut`
+
+error: the semantics of this pattern will change in edition 2024
+  --> $DIR/match_ergonomics_2024.rs:22:12
+   |
+LL |     if let Some(&_) = &&&&&Some(&0u8) {}
+   |            -^^^^^^^
+   |            |
+   |            help: desugar the match ergonomics: `&&&&&`
+
+error: the semantics of this pattern will change in edition 2024
+  --> $DIR/match_ergonomics_2024.rs:25:12
+   |
+LL |     if let Some(&mut _) = &&&&&Some(&mut 0u8) {}
+   |            -^^^^^^^^^^^
+   |            |
+   |            help: desugar the match ergonomics: `&&&&&`
+
+error: the semantics of this pattern will change in edition 2024
+  --> $DIR/match_ergonomics_2024.rs:28:12
+   |
+LL |     if let Some(&_) = &&&&&mut Some(&0u8) {}
+   |            -^^^^^^^
+   |            |
+   |            help: desugar the match ergonomics: `&&&&&mut`
+
+error: the semantics of this pattern will change in edition 2024
+  --> $DIR/match_ergonomics_2024.rs:31:12
+   |
+LL |     if let Some(&mut Some(Some(_))) = &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))) {}
+   |            ++++                ++++
+
+error: the semantics of this pattern will change in edition 2024
+  --> $DIR/match_ergonomics_2024.rs:34:12
+   |
+LL |     if let Some(&mut Some(Some(_a))) = &mut Some(&mut Some(&mut Some(0u8))) {}
+   |            ^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+help: desugar the match ergonomics
+   |
+LL |     if let &mut Some(&mut Some(&mut Some(ref mut _a))) = &mut Some(&mut Some(&mut Some(0u8))) {}
+   |            ++++                ++++      +++++++
+
+error: the semantics of this pattern will change in edition 2024
+  --> $DIR/match_ergonomics_2024.rs:43:9
+   |
+LL |     let Struct { a, mut b, c } = &s;
+   |         ^^^^^^^^^^^^^^^^^^^^^^
+   |
+help: desugar the match ergonomics
+   |
+LL |     let &Struct { ref a, mut b, ref c } = &s;
+   |         +         +++           +++
+
+warning: the semantics of this pattern will change in edition 2024
+  --> $DIR/match_ergonomics_2024.rs:50:9
+   |
+LL |         (Some(mut _x), match_ergonomics_2024_macros::mixed_edition_pat!(_y)) => {
+   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+note: the lint level is defined here
+  --> $DIR/match_ergonomics_2024.rs:46:12
+   |
+LL |     #[warn(rust_2024_incompatible_pat)]
+   |            ^^^^^^^^^^^^^^^^^^^^^^^^^^
+help: desugar the match ergonomics
+   |
+LL |         &(Some(mut _x), match_ergonomics_2024_macros::mixed_edition_pat!(ref _y)) => {
+   |         +                                                                +++
+
+error: aborting due to 8 previous errors; 1 warning emitted
+
diff --git a/tests/ui/pattern/mut_preserve_binding_mode_2024_lint.rs b/tests/ui/pattern/mut_preserve_binding_mode_2024_lint.rs
deleted file mode 100644
index 249f251d2cd..00000000000
--- a/tests/ui/pattern/mut_preserve_binding_mode_2024_lint.rs
+++ /dev/null
@@ -1,16 +0,0 @@
-//@ edition: 2021
-#![feature(mut_preserve_binding_mode_2024)]
-#![allow(incomplete_features, unused)]
-#![forbid(dereferencing_mut_binding)]
-
-struct Foo(u8);
-
-fn main() {
-    let Foo(mut a) = &Foo(0);
-    //~^ ERROR: dereferencing `mut` binding
-    a = 42;
-
-    let Foo(mut a) = &mut Foo(0);
-    //~^ ERROR: dereferencing `mut` binding
-    a = 42;
-}
diff --git a/tests/ui/pattern/mut_preserve_binding_mode_2024_lint.stderr b/tests/ui/pattern/mut_preserve_binding_mode_2024_lint.stderr
deleted file mode 100644
index e8d11acd83e..00000000000
--- a/tests/ui/pattern/mut_preserve_binding_mode_2024_lint.stderr
+++ /dev/null
@@ -1,31 +0,0 @@
-error: dereferencing `mut` binding
-  --> $DIR/mut_preserve_binding_mode_2024_lint.rs:9:13
-   |
-LL |     let Foo(mut a) = &Foo(0);
-   |             ^^^^^ `mut` dereferences the type of this binding
-   |
-help: this will change in edition 2024
-  --> $DIR/mut_preserve_binding_mode_2024_lint.rs:9:13
-   |
-LL |     let Foo(mut a) = &Foo(0);
-   |             ^^^^^
-note: the lint level is defined here
-  --> $DIR/mut_preserve_binding_mode_2024_lint.rs:4:11
-   |
-LL | #![forbid(dereferencing_mut_binding)]
-   |           ^^^^^^^^^^^^^^^^^^^^^^^^^
-
-error: dereferencing `mut` binding
-  --> $DIR/mut_preserve_binding_mode_2024_lint.rs:13:13
-   |
-LL |     let Foo(mut a) = &mut Foo(0);
-   |             ^^^^^ `mut` dereferences the type of this binding
-   |
-help: this will change in edition 2024
-  --> $DIR/mut_preserve_binding_mode_2024_lint.rs:13:13
-   |
-LL |     let Foo(mut a) = &mut Foo(0);
-   |             ^^^^^
-
-error: aborting due to 2 previous errors
-