From 6b7fcf720a714b07ab8dc5d21aac03ade62bbdcc Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Tue, 14 Dec 2021 22:44:27 -0700 Subject: [PATCH] fix(rustc_lint): better detect when parens are necessary Fixes #90807 --- compiler/rustc_lint/src/unused.rs | 5 ++++- src/test/ui/lint/unused/issue-90807-unused-paren.rs | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/lint/unused/issue-90807-unused-paren.rs 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 }) {} +}