diff options
| author | Michael Howell <michael@notriddle.com> | 2021-12-14 22:44:27 -0700 |
|---|---|---|
| committer | Michael Howell <michael@notriddle.com> | 2021-12-15 00:00:17 -0700 |
| commit | 6b7fcf720a714b07ab8dc5d21aac03ade62bbdcc (patch) | |
| tree | b628a9cef386dd35aa18939893530fe8cba13240 | |
| parent | d594910a2da12f158477b4c7281716f535cfa3de (diff) | |
| download | rust-6b7fcf720a714b07ab8dc5d21aac03ade62bbdcc.tar.gz rust-6b7fcf720a714b07ab8dc5d21aac03ade62bbdcc.zip | |
fix(rustc_lint): better detect when parens are necessary
Fixes #90807
| -rw-r--r-- | compiler/rustc_lint/src/unused.rs | 5 | ||||
| -rw-r--r-- | src/test/ui/lint/unused/issue-90807-unused-paren.rs | 8 |
2 files changed, 12 insertions, 1 deletions
diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs index da1edcf6fe3..23a5407950e 100644 --- a/compiler/rustc_lint/src/unused.rs +++ b/compiler/rustc_lint/src/unused.rs @@ -476,8 +476,11 @@ trait UnusedDelimLint { lhs_needs_parens || (followed_by_block - && match inner.kind { + && match &inner.kind { ExprKind::Ret(_) | ExprKind::Break(..) | ExprKind::Yield(..) => true, + ExprKind::Range(_lhs, Some(rhs), _limits) => { + !classify::expr_requires_semi_to_be_stmt(&rhs) + } _ => parser::contains_exterior_struct_lit(&inner), }) } diff --git a/src/test/ui/lint/unused/issue-90807-unused-paren.rs b/src/test/ui/lint/unused/issue-90807-unused-paren.rs new file mode 100644 index 00000000000..4c0930f967d --- /dev/null +++ b/src/test/ui/lint/unused/issue-90807-unused-paren.rs @@ -0,0 +1,8 @@ +// check-pass +// Make sure unused parens lint doesn't emit a false positive. +// See https://github.com/rust-lang/rust/issues/90807 +#![deny(unused_parens)] + +fn main() { + for _ in (1..{ 2 }) {} +} |
