forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
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 rust-lang#123311 - Jules-Bertholet:andpat-everywhere,…
… r=Nadrieril Match ergonomics: implement "`&`pat everywhere" Implements the eat-two-layers (feature gate `and_pat_everywhere`, all editions) ~and the eat-one-layer (feature gate `and_eat_one_layer_2024`, edition 2024 only, takes priority on that edition when both feature gates are active)~ (EDIT: will be done in later PR) semantics. cc rust-lang#123076 r? `@Nadrieril` `@rustbot` label A-patterns A-edition-2024
- Loading branch information
Showing
11 changed files
with
281 additions
and
28 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
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 @@ | ||
pub fn main() { | ||
if let Some(Some(&x)) = &Some(&Some(0)) { | ||
//~^ ERROR: mismatched types [E0308] | ||
let _: u32 = x; | ||
} | ||
if let Some(&Some(x)) = &Some(Some(0)) { | ||
//~^ ERROR: mismatched types [E0308] | ||
let _: u32 = x; | ||
} | ||
if let Some(Some(&mut x)) = &mut Some(&mut Some(0)) { | ||
//~^ ERROR: mismatched types [E0308] | ||
let _: u32 = x; | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
tests/ui/feature-gates/feature-gate-ref_pat_everywhere.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,49 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/feature-gate-ref_pat_everywhere.rs:2:22 | ||
| | ||
LL | if let Some(Some(&x)) = &Some(&Some(0)) { | ||
| ^^ --------------- this expression has type `&Option<&Option<{integer}>>` | ||
| | | ||
| expected integer, found `&_` | ||
| | ||
= note: expected type `{integer}` | ||
found reference `&_` | ||
help: consider removing `&` from the pattern | ||
| | ||
LL | if let Some(Some(x)) = &Some(&Some(0)) { | ||
| ~ | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/feature-gate-ref_pat_everywhere.rs:6:17 | ||
| | ||
LL | if let Some(&Some(x)) = &Some(Some(0)) { | ||
| ^^^^^^^^ -------------- this expression has type `&Option<Option<{integer}>>` | ||
| | | ||
| expected `Option<{integer}>`, found `&_` | ||
| | ||
= note: expected enum `Option<{integer}>` | ||
found reference `&_` | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/feature-gate-ref_pat_everywhere.rs:10:22 | ||
| | ||
LL | if let Some(Some(&mut x)) = &mut Some(&mut Some(0)) { | ||
| ^^^^^^ ----------------------- this expression has type `&mut Option<&mut Option<{integer}>>` | ||
| | | ||
| expected integer, found `&mut _` | ||
| | ||
= note: expected type `{integer}` | ||
found mutable reference `&mut _` | ||
note: to declare a mutable binding use: `mut x` | ||
--> $DIR/feature-gate-ref_pat_everywhere.rs:10:22 | ||
| | ||
LL | if let Some(Some(&mut x)) = &mut Some(&mut Some(0)) { | ||
| ^^^^^^ | ||
help: consider removing `&mut` from the pattern | ||
| | ||
LL | if let Some(Some(x)) = &mut Some(&mut Some(0)) { | ||
| ~ | ||
|
||
error: aborting due to 3 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 @@ | ||
#![allow(incomplete_features)] | ||
#![feature(ref_pat_everywhere)] | ||
pub fn main() { | ||
if let Some(&x) = Some(0) { | ||
//~^ ERROR: mismatched types [E0308] | ||
let _: u32 = x; | ||
} | ||
if let &Some(x) = &mut Some(0) { | ||
//~^ ERROR: mismatched types [E0308] | ||
let _: u32 = x; | ||
} | ||
if let Some(&x) = &mut Some(0) { | ||
//~^ ERROR: mismatched types [E0308] | ||
let _: u32 = x; | ||
} | ||
} |
Oops, something went wrong.