diff options
| author | Manish Goregaokar <manishsmail@gmail.com> | 2020-08-02 13:08:45 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-08-02 13:08:45 -0700 |
| commit | db3e10f9cb6b2e925ae73cd5230df98746640b34 (patch) | |
| tree | 4d1e532bc1a23a64e8c9eda7442c35edc3a02ddd | |
| parent | 1b350ecb60aa1ec1d0eb58b43ebf6a335dc8076c (diff) | |
| parent | 2e7ba785b34b040154761d42bdd4a208707e0d29 (diff) | |
| download | rust-db3e10f9cb6b2e925ae73cd5230df98746640b34.tar.gz rust-db3e10f9cb6b2e925ae73cd5230df98746640b34.zip | |
Rollup merge of #75031 - JohnTitor:unused-parens-braces-yield, r=lcnr
Do not trigger `unused_{braces,parens}` lints with `yield`
Fixes #74883
r? @lcnr
| -rw-r--r-- | src/librustc_lint/unused.rs | 2 | ||||
| -rw-r--r-- | src/test/ui/lint/issue-74883-unused-paren-baren-yield.rs | 33 | ||||
| -rw-r--r-- | src/test/ui/lint/issue-74883-unused-paren-baren-yield.stderr | 62 |
3 files changed, 96 insertions, 1 deletions
diff --git a/src/librustc_lint/unused.rs b/src/librustc_lint/unused.rs index 8d8fb8c3c60..a33f9206035 100644 --- a/src/librustc_lint/unused.rs +++ b/src/librustc_lint/unused.rs @@ -422,7 +422,7 @@ trait UnusedDelimLint { lhs_needs_parens || (followed_by_block && match inner.kind { - ExprKind::Ret(_) | ExprKind::Break(..) => true, + ExprKind::Ret(_) | ExprKind::Break(..) | ExprKind::Yield(..) => true, _ => parser::contains_exterior_struct_lit(&inner), }) } diff --git a/src/test/ui/lint/issue-74883-unused-paren-baren-yield.rs b/src/test/ui/lint/issue-74883-unused-paren-baren-yield.rs new file mode 100644 index 00000000000..02182ec2993 --- /dev/null +++ b/src/test/ui/lint/issue-74883-unused-paren-baren-yield.rs @@ -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)); +} diff --git a/src/test/ui/lint/issue-74883-unused-paren-baren-yield.stderr b/src/test/ui/lint/issue-74883-unused-paren-baren-yield.stderr new file mode 100644 index 00000000000..267cc9e031a --- /dev/null +++ b/src/test/ui/lint/issue-74883-unused-paren-baren-yield.stderr @@ -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 + |
