-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #123535 - Jules-Bertholet:mut_dont_reset_binding_mode…
…_2024, r=Nadrieril Match ergonomics 2024: `mut` doesn't reset binding mode r? ``@Nadrieril`` cc #123076 ``@rustbot`` label A-edition-2024 A-patterns
- Loading branch information
Showing
13 changed files
with
225 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
tests/ui/pattern/feature-gate-mut_preserve_binding_mode_2024.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
31 changes: 31 additions & 0 deletions
31
tests/ui/pattern/feature-gate-mut_preserve_binding_mode_2024.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/feature-gate-mut_preserve_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_preserve_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`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
//@ edition: 2021 | ||
//@ compile-flags: -Zunstable-options | ||
#![feature(mut_preserve_binding_mode_2024)] | ||
#![allow(incomplete_features)] | ||
|
||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/mut_preserve_binding_mode_2021.rs:10: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_preserve_binding_mode_2021.rs:14: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`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
//@ run-pass | ||
//@ edition: 2024 | ||
//@ compile-flags: -Zunstable-options | ||
#![feature(mut_preserve_binding_mode_2024)] | ||
#![allow(incomplete_features, unused)] | ||
|
||
struct Foo(u8); | ||
|
||
fn main() { | ||
let Foo(mut a) = &Foo(0); | ||
a = &42; | ||
|
||
let Foo(mut a) = &mut Foo(0); | ||
a = &mut 42; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
//@ 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; | ||
} |
31 changes: 31 additions & 0 deletions
31
tests/ui/pattern/mut_preserve_binding_mode_2024_lint.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
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 | ||
|