about summary refs log tree commit diff
path: root/tests/ui/pattern
diff options
context:
space:
mode:
authordianne <diannes.gm@gmail.com>2025-01-26 00:27:37 -0800
committerdianne <diannes.gm@gmail.com>2025-02-18 17:44:28 -0800
commit443c51d5d6eb0903e3eef9a44e1dfb017e69958d (patch)
tree8057bea612110ec624988c64bf12960b10a89c6b /tests/ui/pattern
parent8dc64a405d53f30fef4a080afb68d10e59318a3d (diff)
downloadrust-443c51d5d6eb0903e3eef9a44e1dfb017e69958d.tar.gz
rust-443c51d5d6eb0903e3eef9a44e1dfb017e69958d.zip
"structural2021" ruleset: add fallback-to-outer (eat both) deref rule
Diffstat (limited to 'tests/ui/pattern')
-rw-r--r--tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/well-typed-edition-2024.classic2021.stderr52
-rw-r--r--tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/well-typed-edition-2024.rs47
-rw-r--r--tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/well-typed-edition-2024.stable2021.stderr52
-rw-r--r--tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/well-typed-edition-2024.structural2021.stderr136
4 files changed, 114 insertions, 173 deletions
diff --git a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/well-typed-edition-2024.classic2021.stderr b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/well-typed-edition-2024.classic2021.stderr
index f784d7e9988..086d4bb133b 100644
--- a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/well-typed-edition-2024.classic2021.stderr
+++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/well-typed-edition-2024.classic2021.stderr
@@ -105,28 +105,7 @@ LL +     let [ref x] = &mut [&0];
    |
 
 error[E0308]: mismatched types
-  --> $DIR/well-typed-edition-2024.rs:108:10
-   |
-LL |     let [&mut ref mut x] = &mut [&0];
-   |          ^^^^^^^^^^^^^^    --------- this expression has type `&mut [&{integer}; 1]`
-   |          |
-   |          types differ in mutability
-   |
-   = note:      expected reference `&{integer}`
-           found mutable reference `&mut _`
-note: to declare a mutable binding use: `mut x`
-  --> $DIR/well-typed-edition-2024.rs:108:10
-   |
-LL |     let [&mut ref mut x] = &mut [&0];
-   |          ^^^^^^^^^^^^^^
-help: consider removing `&mut` from the pattern
-   |
-LL -     let [&mut ref mut x] = &mut [&0];
-LL +     let [ref mut x] = &mut [&0];
-   |
-
-error[E0308]: mismatched types
-  --> $DIR/well-typed-edition-2024.rs:114:10
+  --> $DIR/well-typed-edition-2024.rs:117:10
    |
 LL |     let [&mut mut x] = &mut [&0];
    |          ^^^^^^^^^^    --------- this expression has type `&mut [&{integer}; 1]`
@@ -136,7 +115,7 @@ LL |     let [&mut mut x] = &mut [&0];
    = note:      expected reference `&{integer}`
            found mutable reference `&mut _`
 note: to declare a mutable binding use: `mut x`
-  --> $DIR/well-typed-edition-2024.rs:114:10
+  --> $DIR/well-typed-edition-2024.rs:117:10
    |
 LL |     let [&mut mut x] = &mut [&0];
    |          ^^^^^^^^^^
@@ -147,7 +126,7 @@ LL +     let [mut x] = &mut [&0];
    |
 
 error[E0308]: mismatched types
-  --> $DIR/well-typed-edition-2024.rs:120:10
+  --> $DIR/well-typed-edition-2024.rs:123:10
    |
 LL |     let [&mut &x] = &mut [&0];
    |          ^^^^^^^    --------- this expression has type `&mut [&{integer}; 1]`
@@ -158,7 +137,7 @@ LL |     let [&mut &x] = &mut [&0];
            found mutable reference `&mut _`
 
 error[E0308]: mismatched types
-  --> $DIR/well-typed-edition-2024.rs:126:10
+  --> $DIR/well-typed-edition-2024.rs:129:10
    |
 LL |     let [&mut &ref x] = &mut [&0];
    |          ^^^^^^^^^^^    --------- this expression has type `&mut [&{integer}; 1]`
@@ -169,7 +148,7 @@ LL |     let [&mut &ref x] = &mut [&0];
            found mutable reference `&mut _`
 
 error[E0308]: mismatched types
-  --> $DIR/well-typed-edition-2024.rs:132:10
+  --> $DIR/well-typed-edition-2024.rs:135:10
    |
 LL |     let [&mut &(mut x)] = &mut [&0];
    |          ^^^^^^^^^^^^^    --------- this expression has type `&mut [&{integer}; 1]`
@@ -179,6 +158,27 @@ LL |     let [&mut &(mut x)] = &mut [&0];
    = note:      expected reference `&{integer}`
            found mutable reference `&mut _`
 
+error[E0308]: mismatched types
+  --> $DIR/well-typed-edition-2024.rs:109:14
+   |
+LL |         let [&mut ref mut x] = &mut [&0];
+   |              ^^^^^^^^^^^^^^    --------- this expression has type `&mut [&{integer}; 1]`
+   |              |
+   |              types differ in mutability
+   |
+   = note:      expected reference `&{integer}`
+           found mutable reference `&mut _`
+note: to declare a mutable binding use: `mut x`
+  --> $DIR/well-typed-edition-2024.rs:109:14
+   |
+LL |         let [&mut ref mut x] = &mut [&0];
+   |              ^^^^^^^^^^^^^^
+help: consider removing `&mut` from the pattern
+   |
+LL -         let [&mut ref mut x] = &mut [&0];
+LL +         let [ref mut x] = &mut [&0];
+   |
+
 error: aborting due to 11 previous errors
 
 For more information about this error, try `rustc --explain E0308`.
diff --git a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/well-typed-edition-2024.rs b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/well-typed-edition-2024.rs
index 851011918fe..63a09fe90c9 100644
--- a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/well-typed-edition-2024.rs
+++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/well-typed-edition-2024.rs
@@ -91,47 +91,50 @@ pub fn main() {
         #[cfg(any(classic2024, structural2024))] let _: u32 = x;
     }
 
-    // Tests for eat-inner rulesets matching on the outer reference if matching on the inner
-    // reference causes a mutability mismatch, i.e. `Deref(EatInner, FallbackToOuter)`:
+    // Tests for eat-inner and eat-both rulesets matching on the outer reference if matching on the
+    // inner reference causes a mutability mismatch. i.e. tests for "fallback-to-outer" deref rules.
     let [&mut x] = &mut [&0];
-    //[stable2021,classic2021,structural2021]~^ mismatched types
-    //[stable2021,classic2021,structural2021]~| types differ in mutability
-    // TODO: on `structural2021` `x` should have type `u32`
+    //[stable2021,classic2021]~^ mismatched types
+    //[stable2021,classic2021]~| types differ in mutability
+    #[cfg(structural2021)] let _: u32 = x;
     #[cfg(any(classic2024, structural2024))] let _: &u32 = x;
 
     let [&mut ref x] = &mut [&0];
-    //[stable2021,classic2021,structural2021]~^ mismatched types
-    //[stable2021,classic2021,structural2021]~| types differ in mutability
-    // TODO: on `structural2021` `x` should have type `&u32`
+    //[stable2021,classic2021]~^ mismatched types
+    //[stable2021,classic2021]~| types differ in mutability
+    #[cfg(structural2021)] let _: &u32 = x;
     #[cfg(any(classic2024, structural2024))] let _: &&u32 = x;
 
-    let [&mut ref mut x] = &mut [&0];
-    //[stable2021,classic2021,structural2021]~^ mismatched types
-    //[stable2021,classic2021,structural2021]~| types differ in mutability
-    // TODO: this should be a mut borrow behind shared borrow error on `structural2021`
-    #[cfg(any(classic2024, structural2024))] let _: &mut &u32 = x;
+    fn borrowck_error_on_structural2021() {
+        let [&mut ref mut x] = &mut [&0];
+        //[stable2021,classic2021]~^ mismatched types
+        //[stable2021,classic2021]~| types differ in mutability
+        //[structural2021]~^^^ cannot borrow data in a `&` reference as mutable
+        #[cfg(any(classic2024, structural2024))] let _: &mut &u32 = x;
+    }
+    borrowck_error_on_structural2021();
 
     let [&mut mut x] = &mut [&0];
-    //[stable2021,classic2021,structural2021]~^ mismatched types
-    //[stable2021,classic2021,structural2021]~| types differ in mutability
-    // TODO: on `structural2021` `x` should have type `u32`
+    //[stable2021,classic2021]~^ mismatched types
+    //[stable2021,classic2021]~| types differ in mutability
+    #[cfg(structural2021)] let _: u32 = x;
     #[cfg(any(classic2024, structural2024))] let _: &u32 = x;
 
     let [&mut &x] = &mut [&0];
     //[stable2021,classic2021,structural2021]~^ mismatched types
-    //[stable2021,classic2021,structural2021]~| types differ in mutability
-    // TODO: [structural2021]~| expected integer, found `&_`
+    //[stable2021,classic2021]~| types differ in mutability
+    //[structural2021]~| expected integer, found `&_`
     #[cfg(any(classic2024, structural2024))] let _: u32 = x;
 
     let [&mut &ref x] = &mut [&0];
     //[stable2021,classic2021,structural2021]~^ mismatched types
-    //[stable2021,classic2021,structural2021]~| types differ in mutability
-    // TODO: [structural2021]~| expected integer, found `&_`
+    //[stable2021,classic2021]~| types differ in mutability
+    //[structural2021]~| expected integer, found `&_`
     #[cfg(any(classic2024, structural2024))] let _: &u32 = x;
 
     let [&mut &(mut x)] = &mut [&0];
     //[stable2021,classic2021,structural2021]~^ mismatched types
-    //[stable2021,classic2021,structural2021]~| types differ in mutability
-    // TODO: [structural2021]~| expected integer, found `&_`
+    //[stable2021,classic2021]~| types differ in mutability
+    //[structural2021]~| expected integer, found `&_`
     #[cfg(any(classic2024, structural2024))] let _: u32 = x;
 }
diff --git a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/well-typed-edition-2024.stable2021.stderr b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/well-typed-edition-2024.stable2021.stderr
index fb99e3983e8..adb47172f34 100644
--- a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/well-typed-edition-2024.stable2021.stderr
+++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/well-typed-edition-2024.stable2021.stderr
@@ -186,28 +186,7 @@ LL +     let [ref x] = &mut [&0];
    |
 
 error[E0308]: mismatched types
-  --> $DIR/well-typed-edition-2024.rs:108:10
-   |
-LL |     let [&mut ref mut x] = &mut [&0];
-   |          ^^^^^^^^^^^^^^    --------- this expression has type `&mut [&{integer}; 1]`
-   |          |
-   |          types differ in mutability
-   |
-   = note:      expected reference `&{integer}`
-           found mutable reference `&mut _`
-note: to declare a mutable binding use: `mut x`
-  --> $DIR/well-typed-edition-2024.rs:108:10
-   |
-LL |     let [&mut ref mut x] = &mut [&0];
-   |          ^^^^^^^^^^^^^^
-help: consider removing `&mut` from the pattern
-   |
-LL -     let [&mut ref mut x] = &mut [&0];
-LL +     let [ref mut x] = &mut [&0];
-   |
-
-error[E0308]: mismatched types
-  --> $DIR/well-typed-edition-2024.rs:114:10
+  --> $DIR/well-typed-edition-2024.rs:117:10
    |
 LL |     let [&mut mut x] = &mut [&0];
    |          ^^^^^^^^^^    --------- this expression has type `&mut [&{integer}; 1]`
@@ -217,7 +196,7 @@ LL |     let [&mut mut x] = &mut [&0];
    = note:      expected reference `&{integer}`
            found mutable reference `&mut _`
 note: to declare a mutable binding use: `mut x`
-  --> $DIR/well-typed-edition-2024.rs:114:10
+  --> $DIR/well-typed-edition-2024.rs:117:10
    |
 LL |     let [&mut mut x] = &mut [&0];
    |          ^^^^^^^^^^
@@ -228,7 +207,7 @@ LL +     let [mut x] = &mut [&0];
    |
 
 error[E0308]: mismatched types
-  --> $DIR/well-typed-edition-2024.rs:120:10
+  --> $DIR/well-typed-edition-2024.rs:123:10
    |
 LL |     let [&mut &x] = &mut [&0];
    |          ^^^^^^^    --------- this expression has type `&mut [&{integer}; 1]`
@@ -239,7 +218,7 @@ LL |     let [&mut &x] = &mut [&0];
            found mutable reference `&mut _`
 
 error[E0308]: mismatched types
-  --> $DIR/well-typed-edition-2024.rs:126:10
+  --> $DIR/well-typed-edition-2024.rs:129:10
    |
 LL |     let [&mut &ref x] = &mut [&0];
    |          ^^^^^^^^^^^    --------- this expression has type `&mut [&{integer}; 1]`
@@ -250,7 +229,7 @@ LL |     let [&mut &ref x] = &mut [&0];
            found mutable reference `&mut _`
 
 error[E0308]: mismatched types
-  --> $DIR/well-typed-edition-2024.rs:132:10
+  --> $DIR/well-typed-edition-2024.rs:135:10
    |
 LL |     let [&mut &(mut x)] = &mut [&0];
    |          ^^^^^^^^^^^^^    --------- this expression has type `&mut [&{integer}; 1]`
@@ -260,6 +239,27 @@ LL |     let [&mut &(mut x)] = &mut [&0];
    = note:      expected reference `&{integer}`
            found mutable reference `&mut _`
 
+error[E0308]: mismatched types
+  --> $DIR/well-typed-edition-2024.rs:109:14
+   |
+LL |         let [&mut ref mut x] = &mut [&0];
+   |              ^^^^^^^^^^^^^^    --------- this expression has type `&mut [&{integer}; 1]`
+   |              |
+   |              types differ in mutability
+   |
+   = note:      expected reference `&{integer}`
+           found mutable reference `&mut _`
+note: to declare a mutable binding use: `mut x`
+  --> $DIR/well-typed-edition-2024.rs:109:14
+   |
+LL |         let [&mut ref mut x] = &mut [&0];
+   |              ^^^^^^^^^^^^^^
+help: consider removing `&mut` from the pattern
+   |
+LL -         let [&mut ref mut x] = &mut [&0];
+LL +         let [ref mut x] = &mut [&0];
+   |
+
 error: aborting due to 17 previous errors
 
 For more information about this error, try `rustc --explain E0308`.
diff --git a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/well-typed-edition-2024.structural2021.stderr b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/well-typed-edition-2024.structural2021.stderr
index f784d7e9988..f8c2bd9a921 100644
--- a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/well-typed-edition-2024.structural2021.stderr
+++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/well-typed-edition-2024.structural2021.stderr
@@ -63,122 +63,60 @@ LL +     if let Some(&Some(x)) = &mut Some(&Some(0)) {
    |
 
 error[E0308]: mismatched types
-  --> $DIR/well-typed-edition-2024.rs:96:10
+  --> $DIR/well-typed-edition-2024.rs:123:15
    |
-LL |     let [&mut x] = &mut [&0];
-   |          ^^^^^^    --------- this expression has type `&mut [&{integer}; 1]`
-   |          |
-   |          types differ in mutability
-   |
-   = note:      expected reference `&{integer}`
-           found mutable reference `&mut _`
-note: to declare a mutable binding use: `mut x`
-  --> $DIR/well-typed-edition-2024.rs:96:10
-   |
-LL |     let [&mut x] = &mut [&0];
-   |          ^^^^^^
-help: consider removing `&mut` from the pattern
-   |
-LL -     let [&mut x] = &mut [&0];
-LL +     let [x] = &mut [&0];
-   |
-
-error[E0308]: mismatched types
-  --> $DIR/well-typed-edition-2024.rs:102:10
-   |
-LL |     let [&mut ref x] = &mut [&0];
-   |          ^^^^^^^^^^    --------- this expression has type `&mut [&{integer}; 1]`
-   |          |
-   |          types differ in mutability
-   |
-   = note:      expected reference `&{integer}`
-           found mutable reference `&mut _`
-note: to declare a mutable binding use: `mut x`
-  --> $DIR/well-typed-edition-2024.rs:102:10
-   |
-LL |     let [&mut ref x] = &mut [&0];
-   |          ^^^^^^^^^^
-help: consider removing `&mut` from the pattern
-   |
-LL -     let [&mut ref x] = &mut [&0];
-LL +     let [ref x] = &mut [&0];
-   |
-
-error[E0308]: mismatched types
-  --> $DIR/well-typed-edition-2024.rs:108:10
-   |
-LL |     let [&mut ref mut x] = &mut [&0];
-   |          ^^^^^^^^^^^^^^    --------- this expression has type `&mut [&{integer}; 1]`
-   |          |
-   |          types differ in mutability
-   |
-   = note:      expected reference `&{integer}`
-           found mutable reference `&mut _`
-note: to declare a mutable binding use: `mut x`
-  --> $DIR/well-typed-edition-2024.rs:108:10
+LL |     let [&mut &x] = &mut [&0];
+   |               ^^    --------- this expression has type `&mut [&{integer}; 1]`
+   |               |
+   |               expected integer, found `&_`
    |
-LL |     let [&mut ref mut x] = &mut [&0];
-   |          ^^^^^^^^^^^^^^
-help: consider removing `&mut` from the pattern
+   = note:   expected type `{integer}`
+           found reference `&_`
+help: consider removing `&` from the pattern
    |
-LL -     let [&mut ref mut x] = &mut [&0];
-LL +     let [ref mut x] = &mut [&0];
+LL -     let [&mut &x] = &mut [&0];
+LL +     let [&mut x] = &mut [&0];
    |
 
 error[E0308]: mismatched types
-  --> $DIR/well-typed-edition-2024.rs:114:10
-   |
-LL |     let [&mut mut x] = &mut [&0];
-   |          ^^^^^^^^^^    --------- this expression has type `&mut [&{integer}; 1]`
-   |          |
-   |          types differ in mutability
+  --> $DIR/well-typed-edition-2024.rs:129:15
    |
-   = note:      expected reference `&{integer}`
-           found mutable reference `&mut _`
-note: to declare a mutable binding use: `mut x`
-  --> $DIR/well-typed-edition-2024.rs:114:10
+LL |     let [&mut &ref x] = &mut [&0];
+   |               ^^^^^^    --------- this expression has type `&mut [&{integer}; 1]`
+   |               |
+   |               expected integer, found `&_`
    |
-LL |     let [&mut mut x] = &mut [&0];
-   |          ^^^^^^^^^^
-help: consider removing `&mut` from the pattern
+   = note:   expected type `{integer}`
+           found reference `&_`
+help: consider removing `&` from the pattern
    |
-LL -     let [&mut mut x] = &mut [&0];
-LL +     let [mut x] = &mut [&0];
+LL -     let [&mut &ref x] = &mut [&0];
+LL +     let [&mut ref x] = &mut [&0];
    |
 
 error[E0308]: mismatched types
-  --> $DIR/well-typed-edition-2024.rs:120:10
+  --> $DIR/well-typed-edition-2024.rs:135:15
    |
-LL |     let [&mut &x] = &mut [&0];
-   |          ^^^^^^^    --------- this expression has type `&mut [&{integer}; 1]`
-   |          |
-   |          types differ in mutability
+LL |     let [&mut &(mut x)] = &mut [&0];
+   |               ^^^^^^^^    --------- this expression has type `&mut [&{integer}; 1]`
+   |               |
+   |               expected integer, found `&_`
    |
-   = note:      expected reference `&{integer}`
-           found mutable reference `&mut _`
-
-error[E0308]: mismatched types
-  --> $DIR/well-typed-edition-2024.rs:126:10
+   = note:   expected type `{integer}`
+           found reference `&_`
+help: consider removing `&` from the pattern
    |
-LL |     let [&mut &ref x] = &mut [&0];
-   |          ^^^^^^^^^^^    --------- this expression has type `&mut [&{integer}; 1]`
-   |          |
-   |          types differ in mutability
+LL -     let [&mut &(mut x)] = &mut [&0];
+LL +     let [&mut mut x)] = &mut [&0];
    |
-   = note:      expected reference `&{integer}`
-           found mutable reference `&mut _`
 
-error[E0308]: mismatched types
-  --> $DIR/well-typed-edition-2024.rs:132:10
-   |
-LL |     let [&mut &(mut x)] = &mut [&0];
-   |          ^^^^^^^^^^^^^    --------- this expression has type `&mut [&{integer}; 1]`
-   |          |
-   |          types differ in mutability
+error[E0596]: cannot borrow data in a `&` reference as mutable
+  --> $DIR/well-typed-edition-2024.rs:109:19
    |
-   = note:      expected reference `&{integer}`
-           found mutable reference `&mut _`
+LL |         let [&mut ref mut x] = &mut [&0];
+   |                   ^^^^^^^^^ cannot borrow as mutable
 
-error: aborting due to 11 previous errors
+error: aborting due to 8 previous errors
 
-For more information about this error, try `rustc --explain E0308`.
+Some errors have detailed explanations: E0308, E0596.
+For more information about an error, try `rustc --explain E0308`.