Gate implicit mutable by-reference bindings behind mut ref

This commit is contained in:
Jules Bertholet
2024-05-15 16:55:54 -04:00
parent eb91f3b051
commit 0746577fa2
11 changed files with 61 additions and 65 deletions

View File

@@ -49,4 +49,14 @@ pub fn main() {
let &mut &mut &mut &mut _ = &mut &&&&mut &&&mut &mut 0;
//~^ ERROR: mismatched types
struct Foo(u8);
let Foo(mut a) = &Foo(0);
//~^ ERROR: binding cannot be both mutable and by-reference
a = &42;
let Foo(mut a) = &mut Foo(0);
//~^ ERROR: binding cannot be both mutable and by-reference
a = &mut 42;
}

View File

@@ -152,6 +152,27 @@ LL | let &mut &mut &mut &mut _ = &mut &&&&mut &&&mut &mut 0;
= note: expected reference `&&&&mut &&&mut &mut {integer}`
found mutable reference `&mut _`
error: aborting due to 14 previous errors
error[E0658]: binding cannot be both mutable and by-reference
--> $DIR/ref_pat_eat_one_layer_2024_fail.rs:55:13
|
LL | let Foo(mut a) = &Foo(0);
| ^^^^
|
= note: see issue #123076 <https://github.com/rust-lang/rust/issues/123076> for more information
= help: add `#![feature(mut_ref)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
For more information about this error, try `rustc --explain E0308`.
error[E0658]: binding cannot be both mutable and by-reference
--> $DIR/ref_pat_eat_one_layer_2024_fail.rs:59:13
|
LL | let Foo(mut a) = &mut Foo(0);
| ^^^^
|
= note: see issue #123076 <https://github.com/rust-lang/rust/issues/123076> for more information
= help: add `#![feature(mut_ref)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
error: aborting due to 16 previous errors
Some errors have detailed explanations: E0308, E0658.
For more information about an error, try `rustc --explain E0308`.