-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #124567 - Jules-Bertholet:and-eats-andmut, r=Nadrieril
Match ergonomics 2024: let `&` patterns eat `&mut` r? `@Nadrieril` cc #123076 `@rustbot` label A-edition-2024 A-patterns
- Loading branch information
Showing
13 changed files
with
420 additions
and
213 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
30 changes: 30 additions & 0 deletions
30
...s/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2024_ref_mut_inside_and.fixed
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,30 @@ | ||
//@ edition: 2024 | ||
//@ compile-flags: -Zunstable-options | ||
//@ run-rustfix | ||
#![allow(incomplete_features)] | ||
#![feature(ref_pat_eat_one_layer_2024)] | ||
|
||
pub fn main() { | ||
if let Some(&mut Some(ref mut x)) = &mut Some(Some(0)) { | ||
//~^ ERROR: cannot borrow as mutable inside an `&` pattern | ||
let _: &mut u8 = x; | ||
} | ||
|
||
if let &mut Some(Some(ref mut x)) = &mut Some(Some(0)) { | ||
//~^ ERROR: cannot borrow as mutable inside an `&` pattern | ||
let _: &mut u8 = x; | ||
} | ||
|
||
macro_rules! pat { | ||
($var:ident) => { ref mut $var }; | ||
} | ||
let &mut pat!(x) = &mut 0; | ||
//~^ ERROR: cannot borrow as mutable inside an `&` pattern | ||
let _: &mut u8 = x; | ||
|
||
let &mut (ref mut a, ref mut b) = &mut (true, false); | ||
//~^ ERROR: cannot borrow as mutable inside an `&` pattern | ||
//~| ERROR: cannot borrow as mutable inside an `&` pattern | ||
let _: &mut bool = a; | ||
let _: &mut bool = b; | ||
} |
30 changes: 30 additions & 0 deletions
30
tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2024_ref_mut_inside_and.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,30 @@ | ||
//@ edition: 2024 | ||
//@ compile-flags: -Zunstable-options | ||
//@ run-rustfix | ||
#![allow(incomplete_features)] | ||
#![feature(ref_pat_eat_one_layer_2024)] | ||
|
||
pub fn main() { | ||
if let Some(&Some(ref mut x)) = &mut Some(Some(0)) { | ||
//~^ ERROR: cannot borrow as mutable inside an `&` pattern | ||
let _: &mut u8 = x; | ||
} | ||
|
||
if let &Some(Some(ref mut x)) = &mut Some(Some(0)) { | ||
//~^ ERROR: cannot borrow as mutable inside an `&` pattern | ||
let _: &mut u8 = x; | ||
} | ||
|
||
macro_rules! pat { | ||
($var:ident) => { ref mut $var }; | ||
} | ||
let &pat!(x) = &mut 0; | ||
//~^ ERROR: cannot borrow as mutable inside an `&` pattern | ||
let _: &mut u8 = x; | ||
|
||
let &(ref mut a, ref mut b) = &mut (true, false); | ||
//~^ ERROR: cannot borrow as mutable inside an `&` pattern | ||
//~| ERROR: cannot borrow as mutable inside an `&` pattern | ||
let _: &mut bool = a; | ||
let _: &mut bool = b; | ||
} |
43 changes: 43 additions & 0 deletions
43
.../ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2024_ref_mut_inside_and.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,43 @@ | ||
error[E0596]: cannot borrow as mutable inside an `&` pattern | ||
--> $DIR/ref_pat_eat_one_layer_2024_ref_mut_inside_and.rs:8:31 | ||
| | ||
LL | if let Some(&Some(ref mut x)) = &mut Some(Some(0)) { | ||
| - ^ | ||
| | | ||
| help: replace this `&` with `&mut`: `&mut` | ||
|
||
error[E0596]: cannot borrow as mutable inside an `&` pattern | ||
--> $DIR/ref_pat_eat_one_layer_2024_ref_mut_inside_and.rs:13:31 | ||
| | ||
LL | if let &Some(Some(ref mut x)) = &mut Some(Some(0)) { | ||
| - ^ | ||
| | | ||
| help: replace this `&` with `&mut`: `&mut` | ||
|
||
error[E0596]: cannot borrow as mutable inside an `&` pattern | ||
--> $DIR/ref_pat_eat_one_layer_2024_ref_mut_inside_and.rs:21:15 | ||
| | ||
LL | let &pat!(x) = &mut 0; | ||
| - ^ | ||
| | | ||
| help: replace this `&` with `&mut`: `&mut` | ||
|
||
error[E0596]: cannot borrow as mutable inside an `&` pattern | ||
--> $DIR/ref_pat_eat_one_layer_2024_ref_mut_inside_and.rs:25:19 | ||
| | ||
LL | let &(ref mut a, ref mut b) = &mut (true, false); | ||
| - ^ | ||
| | | ||
| help: replace this `&` with `&mut`: `&mut` | ||
|
||
error[E0596]: cannot borrow as mutable inside an `&` pattern | ||
--> $DIR/ref_pat_eat_one_layer_2024_ref_mut_inside_and.rs:25:30 | ||
| | ||
LL | let &(ref mut a, ref mut b) = &mut (true, false); | ||
| - ^ | ||
| | | ||
| help: replace this `&` with `&mut`: `&mut` | ||
|
||
error: aborting due to 5 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0596`. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/ref_pat_everywhere-fail.rs:4:17 | ||
| | ||
LL | if let Some(&x) = Some(0) { | ||
| ^^ ------- this expression has type `Option<{integer}>` | ||
| | | ||
| expected integer, found `&_` | ||
| | ||
= note: expected type `{integer}` | ||
found reference `&_` | ||
help: consider removing `&` from the pattern | ||
| | ||
LL | if let Some(x) = Some(0) { | ||
| ~ | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/ref_pat_everywhere-fail.rs:8:17 | ||
| | ||
LL | if let Some(&mut x) = Some(&0) { | ||
| ^^^^^^ -------- this expression has type `Option<&{integer}>` | ||
| | | ||
| types differ in mutability | ||
| | ||
= note: expected reference `&{integer}` | ||
found mutable reference `&mut _` | ||
note: to declare a mutable binding use: `mut x` | ||
--> $DIR/ref_pat_everywhere-fail.rs:8:17 | ||
| | ||
LL | if let Some(&mut x) = Some(&0) { | ||
| ^^^^^^ | ||
help: consider removing `&mut` from the pattern | ||
| | ||
LL | if let Some(x) = Some(&0) { | ||
| ~ | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0308`. |
44 changes: 0 additions & 44 deletions
44
tests/ui/match/ref_pat_everywhere-mutability-mismatch.stderr
This file was deleted.
Oops, something went wrong.
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