-
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.
Match ergonomics 2024: Implement eat-one-layer
- Loading branch information
1 parent
1921968
commit 2f730c1
Showing
10 changed files
with
472 additions
and
51 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
37 changes: 37 additions & 0 deletions
37
tests/ui/match/ref_pat_eat_one_layer_2024/feature-gate-ref_pat_eat_one_layer_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,37 @@ | ||
//@ edition: 2024 | ||
//@ compile-flags: -Zunstable-options | ||
|
||
pub fn main() { | ||
if let Some(Some(&x)) = &Some(&Some(0)) { | ||
//~^ ERROR: mismatched types | ||
let _: u32 = x; | ||
} | ||
if let Some(Some(&x)) = &Some(Some(&0)) { | ||
let _: &u32 = x; | ||
//~^ ERROR: mismatched types | ||
} | ||
if let Some(Some(&&x)) = &Some(Some(&0)) { | ||
//~^ ERROR: mismatched types | ||
let _: u32 = x; | ||
} | ||
if let Some(&Some(x)) = &Some(Some(0)) { | ||
//~^ ERROR: mismatched types | ||
let _: u32 = x; | ||
} | ||
if let Some(Some(&mut x)) = &mut Some(&mut Some(0)) { | ||
//~^ ERROR: mismatched types | ||
let _: u32 = x; | ||
} | ||
if let Some(Some(&x)) = &Some(&Some(0)) { | ||
//~^ ERROR: mismatched types | ||
let _: u32 = x; | ||
} | ||
if let Some(&mut Some(&x)) = &Some(&mut Some(0)) { | ||
//~^ ERROR: mismatched types | ||
let _: u32 = x; | ||
} | ||
if let Some(&Some(&mut x)) = &mut Some(&Some(0)) { | ||
//~^ ERROR: mismatched types | ||
let _: u32 = x; | ||
} | ||
} |
128 changes: 128 additions & 0 deletions
128
tests/ui/match/ref_pat_eat_one_layer_2024/feature-gate-ref_pat_eat_one_layer_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,128 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/feature-gate-ref_pat_eat_one_layer_2024.rs:5: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_eat_one_layer_2024.rs:10:23 | ||
| | ||
LL | let _: &u32 = x; | ||
| ---- ^ expected `&u32`, found integer | ||
| | | ||
| expected due to this | ||
| | ||
help: consider borrowing here | ||
| | ||
LL | let _: &u32 = &x; | ||
| + | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/feature-gate-ref_pat_eat_one_layer_2024.rs:13:23 | ||
| | ||
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)) { | ||
LL + if let Some(Some(&x)) = &Some(Some(&0)) { | ||
| | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/feature-gate-ref_pat_eat_one_layer_2024.rs:17: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_eat_one_layer_2024.rs:21: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_eat_one_layer_2024.rs:21: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[E0308]: mismatched types | ||
--> $DIR/feature-gate-ref_pat_eat_one_layer_2024.rs:25: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_eat_one_layer_2024.rs:29:27 | ||
| | ||
LL | if let Some(&mut Some(&x)) = &Some(&mut Some(0)) { | ||
| ^^ ------------------- this expression has type `&Option<&mut Option<{integer}>>` | ||
| | | ||
| expected integer, found `&_` | ||
| | ||
= note: expected type `{integer}` | ||
found reference `&_` | ||
help: consider removing `&` from the pattern | ||
| | ||
LL | if let Some(&mut Some(x)) = &Some(&mut Some(0)) { | ||
| ~ | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/feature-gate-ref_pat_eat_one_layer_2024.rs:33:23 | ||
| | ||
LL | if let Some(&Some(&mut x)) = &mut Some(&Some(0)) { | ||
| ^^^^^^ ------------------- this expression has type `&mut Option<&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_eat_one_layer_2024.rs:33:23 | ||
| | ||
LL | if let Some(&Some(&mut x)) = &mut Some(&Some(0)) { | ||
| ^^^^^^ | ||
help: consider removing `&mut` from the pattern | ||
| | ||
LL | if let Some(&Some(x)) = &mut Some(&Some(0)) { | ||
| ~ | ||
|
||
error: aborting due to 8 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0308`. |
37 changes: 37 additions & 0 deletions
37
tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2021.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,37 @@ | ||
//@ edition: 2021 | ||
#![allow(incomplete_features)] | ||
#![feature(ref_pat_eat_one_layer_2024)] | ||
pub fn main() { | ||
if let Some(Some(&x)) = &Some(&Some(0)) { | ||
//~^ ERROR: mismatched types | ||
let _: u32 = x; | ||
} | ||
if let Some(Some(&x)) = &Some(Some(&0)) { | ||
let _: &u32 = x; | ||
//~^ ERROR: mismatched types | ||
} | ||
if let Some(Some(&&x)) = &Some(Some(&0)) { | ||
//~^ ERROR: mismatched types | ||
let _: u32 = x; | ||
} | ||
if let Some(&Some(x)) = &Some(Some(0)) { | ||
//~^ ERROR: mismatched types | ||
let _: u32 = x; | ||
} | ||
if let Some(Some(&mut x)) = &mut Some(&mut Some(0)) { | ||
//~^ ERROR: mismatched types | ||
let _: u32 = x; | ||
} | ||
if let Some(Some(&x)) = &Some(&Some(0)) { | ||
//~^ ERROR: mismatched types | ||
let _: u32 = x; | ||
} | ||
if let Some(&mut Some(&x)) = &Some(&mut Some(0)) { | ||
//~^ ERROR: mismatched types | ||
let _: u32 = x; | ||
} | ||
if let Some(&Some(&mut x)) = &mut Some(&Some(0)) { | ||
//~^ ERROR: mismatched types | ||
let _: u32 = x; | ||
} | ||
} |
Oops, something went wrong.