fix(rustc_lint): better detect when parens are necessary

Fixes #90807
This commit is contained in:
Michael Howell 2021-12-14 22:44:27 -07:00
parent d594910a2d
commit 6b7fcf720a
2 changed files with 12 additions and 1 deletions

View File

@ -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),
})
}

View File

@ -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 }) {}
}