about summary refs log tree commit diff
path: root/tests/ui/pattern
diff options
context:
space:
mode:
authorJules Bertholet <julesbertholet@quoi.xyz>2024-04-05 23:27:29 -0400
committerJules Bertholet <julesbertholet@quoi.xyz>2024-04-15 23:26:22 -0400
commitef1d084c0b5b0ff7143bbca966442cd24151313b (patch)
tree15c2881af2d553bc9ada9f4f5159dca00d187143 /tests/ui/pattern
parent63f70b3d104e20289a1a0df82747066c3d85b9a1 (diff)
downloadrust-ef1d084c0b5b0ff7143bbca966442cd24151313b.tar.gz
rust-ef1d084c0b5b0ff7143bbca966442cd24151313b.zip
Match ergonomics 2024: `mut` doesn't reset binding mode
Diffstat (limited to 'tests/ui/pattern')
-rw-r--r--tests/ui/pattern/feature-gate-mut_dont_reset_binding_mode_2024.rs14
-rw-r--r--tests/ui/pattern/feature-gate-mut_dont_reset_binding_mode_2024.stderr31
-rw-r--r--tests/ui/pattern/mut_dont_reset_binding_mode_2021.rs15
-rw-r--r--tests/ui/pattern/mut_dont_reset_binding_mode_2021.stderr31
-rw-r--r--tests/ui/pattern/mut_dont_reset_binding_mode_2024.rs15
5 files changed, 106 insertions, 0 deletions
diff --git a/tests/ui/pattern/feature-gate-mut_dont_reset_binding_mode_2024.rs b/tests/ui/pattern/feature-gate-mut_dont_reset_binding_mode_2024.rs
new file mode 100644
index 00000000000..15c542e6bf1
--- /dev/null
+++ b/tests/ui/pattern/feature-gate-mut_dont_reset_binding_mode_2024.rs
@@ -0,0 +1,14 @@
+//@ edition: 2024
+//@ compile-flags: -Zunstable-options
+
+struct Foo(u8);
+
+fn main() {
+    let Foo(mut a) = &Foo(0);
+    a = &42;
+    //~^ ERROR: mismatched types
+
+    let Foo(mut a) = &mut Foo(0);
+    a = &mut 42;
+    //~^ ERROR: mismatched types
+}
diff --git a/tests/ui/pattern/feature-gate-mut_dont_reset_binding_mode_2024.stderr b/tests/ui/pattern/feature-gate-mut_dont_reset_binding_mode_2024.stderr
new file mode 100644
index 00000000000..1624883de60
--- /dev/null
+++ b/tests/ui/pattern/feature-gate-mut_dont_reset_binding_mode_2024.stderr
@@ -0,0 +1,31 @@
+error[E0308]: mismatched types
+  --> $DIR/feature-gate-mut_dont_reset_binding_mode_2024.rs:8:9
+   |
+LL |     let Foo(mut a) = &Foo(0);
+   |             ----- expected due to the type of this binding
+LL |     a = &42;
+   |         ^^^ expected `u8`, found `&{integer}`
+   |
+help: consider removing the borrow
+   |
+LL -     a = &42;
+LL +     a = 42;
+   |
+
+error[E0308]: mismatched types
+  --> $DIR/feature-gate-mut_dont_reset_binding_mode_2024.rs:12:9
+   |
+LL |     let Foo(mut a) = &mut Foo(0);
+   |             ----- expected due to the type of this binding
+LL |     a = &mut 42;
+   |         ^^^^^^^ expected `u8`, found `&mut {integer}`
+   |
+help: consider removing the borrow
+   |
+LL -     a = &mut 42;
+LL +     a = 42;
+   |
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/tests/ui/pattern/mut_dont_reset_binding_mode_2021.rs b/tests/ui/pattern/mut_dont_reset_binding_mode_2021.rs
new file mode 100644
index 00000000000..a9e12472734
--- /dev/null
+++ b/tests/ui/pattern/mut_dont_reset_binding_mode_2021.rs
@@ -0,0 +1,15 @@
+//@ edition: 2021
+//@ compile-flags: -Zunstable-options
+#![feature(mut_dont_reset_binding_mode_2024)]
+
+struct Foo(u8);
+
+fn main() {
+    let Foo(mut a) = &Foo(0);
+    a = &42;
+    //~^ ERROR: mismatched types
+
+    let Foo(mut a) = &mut Foo(0);
+    a = &mut 42;
+    //~^ ERROR: mismatched types
+}
diff --git a/tests/ui/pattern/mut_dont_reset_binding_mode_2021.stderr b/tests/ui/pattern/mut_dont_reset_binding_mode_2021.stderr
new file mode 100644
index 00000000000..16818c900b3
--- /dev/null
+++ b/tests/ui/pattern/mut_dont_reset_binding_mode_2021.stderr
@@ -0,0 +1,31 @@
+error[E0308]: mismatched types
+  --> $DIR/mut_dont_reset_binding_mode_2021.rs:9:9
+   |
+LL |     let Foo(mut a) = &Foo(0);
+   |             ----- expected due to the type of this binding
+LL |     a = &42;
+   |         ^^^ expected `u8`, found `&{integer}`
+   |
+help: consider removing the borrow
+   |
+LL -     a = &42;
+LL +     a = 42;
+   |
+
+error[E0308]: mismatched types
+  --> $DIR/mut_dont_reset_binding_mode_2021.rs:13:9
+   |
+LL |     let Foo(mut a) = &mut Foo(0);
+   |             ----- expected due to the type of this binding
+LL |     a = &mut 42;
+   |         ^^^^^^^ expected `u8`, found `&mut {integer}`
+   |
+help: consider removing the borrow
+   |
+LL -     a = &mut 42;
+LL +     a = 42;
+   |
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/tests/ui/pattern/mut_dont_reset_binding_mode_2024.rs b/tests/ui/pattern/mut_dont_reset_binding_mode_2024.rs
new file mode 100644
index 00000000000..9ac5ec50c74
--- /dev/null
+++ b/tests/ui/pattern/mut_dont_reset_binding_mode_2024.rs
@@ -0,0 +1,15 @@
+//@ run-pass
+//@ edition: 2024
+//@ compile-flags: -Zunstable-options
+#![feature(mut_dont_reset_binding_mode_2024)]
+#![allow(unused)]
+
+struct Foo(u8);
+
+fn main() {
+    let Foo(mut a) = &Foo(0);
+    a = &42;
+
+    let Foo(mut a) = &mut Foo(0);
+    a = &mut 42;
+}