-
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.
Rollup merge of #75031 - JohnTitor:unused-parens-braces-yield, r=lcnr
- Loading branch information
Showing
3 changed files
with
96 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#![feature(generator_trait)] | ||
#![feature(generators)] | ||
#![deny(unused_braces, unused_parens)] | ||
|
||
use std::ops::Generator; | ||
use std::pin::Pin; | ||
|
||
fn main() { | ||
let mut x = |_| { | ||
while let Some(_) = (yield) {} | ||
while let Some(_) = {yield} {} | ||
|
||
// Only warn these cases | ||
while let Some(_) = ({yield}) {} //~ ERROR: unnecessary parentheses | ||
while let Some(_) = ((yield)) {} //~ ERROR: unnecessary parentheses | ||
{{yield}}; //~ ERROR: unnecessary braces | ||
{( yield )}; //~ ERROR: unnecessary parentheses | ||
|
||
// FIXME: Reduce duplicate warnings. | ||
// Perhaps we should tweak checks in `BlockRetValue`? | ||
while let Some(_) = {(yield)} {} | ||
//~^ ERROR: unnecessary braces | ||
//~| ERROR: unnecessary parentheses | ||
while let Some(_) = {{yield}} {} | ||
//~^ ERROR: unnecessary braces | ||
//~| ERROR: unnecessary braces | ||
|
||
// FIXME: It'd be great if we could also warn them. | ||
((yield)); | ||
({ yield }); | ||
}; | ||
let _ = Pin::new(&mut x).resume(Some(5)); | ||
} |
62 changes: 62 additions & 0 deletions
62
src/test/ui/lint/issue-74883-unused-paren-baren-yield.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,62 @@ | ||
error: unnecessary parentheses around `let` scrutinee expression | ||
--> $DIR/issue-74883-unused-paren-baren-yield.rs:14:29 | ||
| | ||
LL | while let Some(_) = ({yield}) {} | ||
| ^^^^^^^^^ help: remove these parentheses | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/issue-74883-unused-paren-baren-yield.rs:3:24 | ||
| | ||
LL | #![deny(unused_braces, unused_parens)] | ||
| ^^^^^^^^^^^^^ | ||
|
||
error: unnecessary parentheses around `let` scrutinee expression | ||
--> $DIR/issue-74883-unused-paren-baren-yield.rs:15:29 | ||
| | ||
LL | while let Some(_) = ((yield)) {} | ||
| ^^^^^^^^^ help: remove these parentheses | ||
|
||
error: unnecessary braces around block return value | ||
--> $DIR/issue-74883-unused-paren-baren-yield.rs:16:10 | ||
| | ||
LL | {{yield}}; | ||
| ^^^^^^^ help: remove these braces | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/issue-74883-unused-paren-baren-yield.rs:3:9 | ||
| | ||
LL | #![deny(unused_braces, unused_parens)] | ||
| ^^^^^^^^^^^^^ | ||
|
||
error: unnecessary parentheses around block return value | ||
--> $DIR/issue-74883-unused-paren-baren-yield.rs:17:10 | ||
| | ||
LL | {( yield )}; | ||
| ^^^^^^^^^ help: remove these parentheses | ||
|
||
error: unnecessary braces around `let` scrutinee expression | ||
--> $DIR/issue-74883-unused-paren-baren-yield.rs:21:29 | ||
| | ||
LL | while let Some(_) = {(yield)} {} | ||
| ^^^^^^^^^ help: remove these braces | ||
|
||
error: unnecessary parentheses around block return value | ||
--> $DIR/issue-74883-unused-paren-baren-yield.rs:21:30 | ||
| | ||
LL | while let Some(_) = {(yield)} {} | ||
| ^^^^^^^ help: remove these parentheses | ||
|
||
error: unnecessary braces around `let` scrutinee expression | ||
--> $DIR/issue-74883-unused-paren-baren-yield.rs:24:29 | ||
| | ||
LL | while let Some(_) = {{yield}} {} | ||
| ^^^^^^^^^ help: remove these braces | ||
|
||
error: unnecessary braces around block return value | ||
--> $DIR/issue-74883-unused-paren-baren-yield.rs:24:30 | ||
| | ||
LL | while let Some(_) = {{yield}} {} | ||
| ^^^^^^^ help: remove these braces | ||
|
||
error: aborting due to 8 previous errors | ||
|