Skip to content

Commit 6b7fcf7

Browse files
committed
fix(rustc_lint): better detect when parens are necessary
Fixes #90807
1 parent d594910 commit 6b7fcf7

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

compiler/rustc_lint/src/unused.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -476,8 +476,11 @@ trait UnusedDelimLint {
476476

477477
lhs_needs_parens
478478
|| (followed_by_block
479-
&& match inner.kind {
479+
&& match &inner.kind {
480480
ExprKind::Ret(_) | ExprKind::Break(..) | ExprKind::Yield(..) => true,
481+
ExprKind::Range(_lhs, Some(rhs), _limits) => {
482+
!classify::expr_requires_semi_to_be_stmt(&rhs)
483+
}
481484
_ => parser::contains_exterior_struct_lit(&inner),
482485
})
483486
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// check-pass
2+
// Make sure unused parens lint doesn't emit a false positive.
3+
// See https://github.com/rust-lang/rust/issues/90807
4+
#![deny(unused_parens)]
5+
6+
fn main() {
7+
for _ in (1..{ 2 }) {}
8+
}

0 commit comments

Comments
 (0)