diff options
| author | Michael Howell <michael@notriddle.com> | 2021-12-17 14:12:31 -0700 |
|---|---|---|
| committer | Michael Howell <michael@notriddle.com> | 2021-12-17 14:12:31 -0700 |
| commit | f4a0321c03884d2f7e71e9850c7524cabdb73c7c (patch) | |
| tree | b1e940ff0faef84df531e2d618e41bce529bbeb4 | |
| parent | 6b7fcf720a714b07ab8dc5d21aac03ade62bbdcc (diff) | |
| download | rust-f4a0321c03884d2f7e71e9850c7524cabdb73c7c.tar.gz rust-f4a0321c03884d2f7e71e9850c7524cabdb73c7c.zip | |
fix(rustc_lint): mark the parens around `(1..loop {})` as unused
| -rw-r--r-- | compiler/rustc_lint/src/unused.rs | 2 | ||||
| -rw-r--r-- | src/test/ui/lint/unused/issue-90807-unused-paren-error.rs | 9 | ||||
| -rw-r--r-- | src/test/ui/lint/unused/issue-90807-unused-paren-error.stderr | 31 |
3 files changed, 41 insertions, 1 deletions
diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs index 23a5407950e..f0ec930345a 100644 --- a/compiler/rustc_lint/src/unused.rs +++ b/compiler/rustc_lint/src/unused.rs @@ -479,7 +479,7 @@ trait UnusedDelimLint { && match &inner.kind { ExprKind::Ret(_) | ExprKind::Break(..) | ExprKind::Yield(..) => true, ExprKind::Range(_lhs, Some(rhs), _limits) => { - !classify::expr_requires_semi_to_be_stmt(&rhs) + matches!(rhs.kind, ExprKind::Block(..)) } _ => parser::contains_exterior_struct_lit(&inner), }) diff --git a/src/test/ui/lint/unused/issue-90807-unused-paren-error.rs b/src/test/ui/lint/unused/issue-90807-unused-paren-error.rs new file mode 100644 index 00000000000..2fca2e26265 --- /dev/null +++ b/src/test/ui/lint/unused/issue-90807-unused-paren-error.rs @@ -0,0 +1,9 @@ +// Make sure unused parens lint emit is emitted for loop and match. +// See https://github.com/rust-lang/rust/issues/90807 +// and https://github.com/rust-lang/rust/pull/91956#discussion_r771647953 +#![deny(unused_parens)] + +fn main() { + for _ in (1..loop { break 2 }) {} //~ERROR + for _ in (1..match () { () => 2 }) {} //~ERROR +} diff --git a/src/test/ui/lint/unused/issue-90807-unused-paren-error.stderr b/src/test/ui/lint/unused/issue-90807-unused-paren-error.stderr new file mode 100644 index 00000000000..4e158e126ac --- /dev/null +++ b/src/test/ui/lint/unused/issue-90807-unused-paren-error.stderr @@ -0,0 +1,31 @@ +error: unnecessary parentheses around `for` iterator expression + --> $DIR/issue-90807-unused-paren-error.rs:7:14 + | +LL | for _ in (1..loop { break 2 }) {} + | ^ ^ + | +note: the lint level is defined here + --> $DIR/issue-90807-unused-paren-error.rs:4:9 + | +LL | #![deny(unused_parens)] + | ^^^^^^^^^^^^^ +help: remove these parentheses + | +LL - for _ in (1..loop { break 2 }) {} +LL + for _ in 1..loop { break 2 } {} + | + +error: unnecessary parentheses around `for` iterator expression + --> $DIR/issue-90807-unused-paren-error.rs:8:14 + | +LL | for _ in (1..match () { () => 2 }) {} + | ^ ^ + | +help: remove these parentheses + | +LL - for _ in (1..match () { () => 2 }) {} +LL + for _ in 1..match () { () => 2 } {} + | + +error: aborting due to 2 previous errors + |
