diff options
| author | Jules Bertholet <julesbertholet@quoi.xyz> | 2024-03-26 01:23:26 -0400 |
|---|---|---|
| committer | Jules Bertholet <julesbertholet@quoi.xyz> | 2024-03-27 11:20:28 -0400 |
| commit | 528d45af18b90ec9833568420a34d4e6050b1ec6 (patch) | |
| tree | f30ed390e50c509fc99045569f021a5b71da7583 /tests/ui/pattern | |
| parent | e0da13f25fd223ee1ec20284ea3f4e88a818b804 (diff) | |
| download | rust-528d45af18b90ec9833568420a34d4e6050b1ec6.tar.gz rust-528d45af18b90ec9833568420a34d4e6050b1ec6.zip | |
Feature gate
Diffstat (limited to 'tests/ui/pattern')
| -rw-r--r-- | tests/ui/pattern/mut-ref-mut-2021.rs | 55 | ||||
| -rw-r--r-- | tests/ui/pattern/mut-ref-mut-2021.stderr | 70 |
2 files changed, 125 insertions, 0 deletions
diff --git a/tests/ui/pattern/mut-ref-mut-2021.rs b/tests/ui/pattern/mut-ref-mut-2021.rs new file mode 100644 index 00000000000..a3be40faeff --- /dev/null +++ b/tests/ui/pattern/mut-ref-mut-2021.rs @@ -0,0 +1,55 @@ +//@ edition: 2021 +#![allow(incomplete_features)] +#![feature(mut_ref)] + +struct Foo(u8); + +fn main() { + let Foo(a) = Foo(0); + a = 42; //~ ERROR [E0384] + + let Foo(mut a) = Foo(0); + a = 42; + + let Foo(ref a) = Foo(0); + a = &42; //~ ERROR [E0384] + + let Foo(mut ref a) = Foo(0); + a = &42; + + let Foo(ref mut a) = Foo(0); + a = &mut 42; //~ ERROR [E0384] + + let Foo(mut ref mut a) = Foo(0); + a = &mut 42; + + let Foo(a) = &Foo(0); + a = &42; //~ ERROR [E0384] + + let Foo(mut a) = &Foo(0); + a = 42; + + let Foo(ref a) = &Foo(0); + a = &42; //~ ERROR [E0384] + + let Foo(mut ref a) = &Foo(0); + a = &42; + + let Foo(a) = &mut Foo(0); + a = &mut 42; //~ ERROR [E0384] + + let Foo(mut a) = &mut Foo(0); + a = 42; + + let Foo(ref a) = &mut Foo(0); + a = &42; //~ ERROR [E0384] + + let Foo(mut ref a) = &mut Foo(0); + a = &42; + + let Foo(ref mut a) = &mut Foo(0); + a = &mut 42; //~ ERROR [E0384] + + let Foo(mut ref mut a) = &mut Foo(0); + a = &mut 42; +} diff --git a/tests/ui/pattern/mut-ref-mut-2021.stderr b/tests/ui/pattern/mut-ref-mut-2021.stderr new file mode 100644 index 00000000000..eb31ffa0e30 --- /dev/null +++ b/tests/ui/pattern/mut-ref-mut-2021.stderr @@ -0,0 +1,70 @@ +error[E0384]: cannot assign twice to immutable variable `a` + --> $DIR/mut-ref-mut-2021.rs:9:5 + | +LL | let Foo(a) = Foo(0); + | - + | | + | first assignment to `a` + | help: consider making this binding mutable: `mut a` +LL | a = 42; + | ^^^^^^ cannot assign twice to immutable variable + +error[E0384]: cannot assign twice to immutable variable `a` + --> $DIR/mut-ref-mut-2021.rs:15:5 + | +LL | let Foo(ref a) = Foo(0); + | ----- first assignment to `a` +LL | a = &42; + | ^^^^^^^ cannot assign twice to immutable variable + +error[E0384]: cannot assign twice to immutable variable `a` + --> $DIR/mut-ref-mut-2021.rs:21:5 + | +LL | let Foo(ref mut a) = Foo(0); + | --------- first assignment to `a` +LL | a = &mut 42; + | ^^^^^^^^^^^ cannot assign twice to immutable variable + +error[E0384]: cannot assign twice to immutable variable `a` + --> $DIR/mut-ref-mut-2021.rs:27:5 + | +LL | let Foo(a) = &Foo(0); + | - first assignment to `a` +LL | a = &42; + | ^^^^^^^ cannot assign twice to immutable variable + +error[E0384]: cannot assign twice to immutable variable `a` + --> $DIR/mut-ref-mut-2021.rs:33:5 + | +LL | let Foo(ref a) = &Foo(0); + | ----- first assignment to `a` +LL | a = &42; + | ^^^^^^^ cannot assign twice to immutable variable + +error[E0384]: cannot assign twice to immutable variable `a` + --> $DIR/mut-ref-mut-2021.rs:39:5 + | +LL | let Foo(a) = &mut Foo(0); + | - first assignment to `a` +LL | a = &mut 42; + | ^^^^^^^^^^^ cannot assign twice to immutable variable + +error[E0384]: cannot assign twice to immutable variable `a` + --> $DIR/mut-ref-mut-2021.rs:45:5 + | +LL | let Foo(ref a) = &mut Foo(0); + | ----- first assignment to `a` +LL | a = &42; + | ^^^^^^^ cannot assign twice to immutable variable + +error[E0384]: cannot assign twice to immutable variable `a` + --> $DIR/mut-ref-mut-2021.rs:51:5 + | +LL | let Foo(ref mut a) = &mut Foo(0); + | --------- first assignment to `a` +LL | a = &mut 42; + | ^^^^^^^^^^^ cannot assign twice to immutable variable + +error: aborting due to 8 previous errors + +For more information about this error, try `rustc --explain E0384`. |
