-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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 #94208 - est31:let_else, r=Mark-Simulacrum
Add the let else tests found missing in the stabilization report In the stabilization report of `let else`, in #93628, I found various cases which weren't tested. This PR adds them.
- Loading branch information
Showing
8 changed files
with
100 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#![feature(let_else)] | ||
|
||
#![deny(unused_variables)] | ||
|
||
fn main() { | ||
let Some(_): Option<u32> = ({ | ||
let x = 1; //~ ERROR unused variable: `x` | ||
Some(1) | ||
}) else { | ||
return; | ||
}; | ||
|
||
#[allow(unused_variables)] | ||
let Some(_): Option<u32> = ({ | ||
let x = 1; | ||
Some(1) | ||
}) else { | ||
return; | ||
}; | ||
|
||
let Some(_): Option<u32> = ({ | ||
#[allow(unused_variables)] | ||
let x = 1; | ||
Some(1) | ||
}) else { | ||
return; | ||
}; | ||
|
||
let x = 1; //~ ERROR unused variable: `x` | ||
} |
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,20 @@ | ||
error: unused variable: `x` | ||
--> $DIR/let-else-allow-in-expr.rs:7:13 | ||
| | ||
LL | let x = 1; | ||
| ^ help: if this is intentional, prefix it with an underscore: `_x` | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/let-else-allow-in-expr.rs:3:9 | ||
| | ||
LL | #![deny(unused_variables)] | ||
| ^^^^^^^^^^^^^^^^ | ||
|
||
error: unused variable: `x` | ||
--> $DIR/let-else-allow-in-expr.rs:29:9 | ||
| | ||
LL | let x = 1; | ||
| ^ help: if this is intentional, prefix it with an underscore: `_x` | ||
|
||
error: aborting due to 2 previous errors | ||
|
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 @@ | ||
error: unused variable: `chaenomeles` | ||
--> $DIR/let-else-allow-unused.rs:14:14 | ||
| | ||
LL | let Some(chaenomeles) = value else { return }; | ||
| ^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_chaenomeles` | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/let-else-allow-unused.rs:5:8 | ||
| | ||
LL | #[deny(unused_variables)] | ||
| ^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
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,9 @@ | ||
// issue #92069 | ||
#![feature(let_else)] | ||
|
||
fn main() { | ||
let nums = vec![5, 4, 3, 2, 1]; | ||
let [x, y] = nums else { //~ ERROR expected an array or slice | ||
return; | ||
}; | ||
} |
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,11 @@ | ||
error[E0529]: expected an array or slice, found `Vec<{integer}>` | ||
--> $DIR/let-else-slicing-error.rs:6:9 | ||
| | ||
LL | let [x, y] = nums else { | ||
| ^^^^^^ ---- help: consider slicing here: `nums[..]` | ||
| | | ||
| pattern cannot match with input type `Vec<{integer}>` | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0529`. |