Skip to content

Commit f4a0321

Browse files
committed
fix(rustc_lint): mark the parens around (1..loop {}) as unused
1 parent 6b7fcf7 commit f4a0321

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

compiler/rustc_lint/src/unused.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ trait UnusedDelimLint {
479479
&& match &inner.kind {
480480
ExprKind::Ret(_) | ExprKind::Break(..) | ExprKind::Yield(..) => true,
481481
ExprKind::Range(_lhs, Some(rhs), _limits) => {
482-
!classify::expr_requires_semi_to_be_stmt(&rhs)
482+
matches!(rhs.kind, ExprKind::Block(..))
483483
}
484484
_ => parser::contains_exterior_struct_lit(&inner),
485485
})
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Make sure unused parens lint emit is emitted for loop and match.
2+
// See https://github.com/rust-lang/rust/issues/90807
3+
// and https://github.com/rust-lang/rust/pull/91956#discussion_r771647953
4+
#![deny(unused_parens)]
5+
6+
fn main() {
7+
for _ in (1..loop { break 2 }) {} //~ERROR
8+
for _ in (1..match () { () => 2 }) {} //~ERROR
9+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
error: unnecessary parentheses around `for` iterator expression
2+
--> $DIR/issue-90807-unused-paren-error.rs:7:14
3+
|
4+
LL | for _ in (1..loop { break 2 }) {}
5+
| ^ ^
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/issue-90807-unused-paren-error.rs:4:9
9+
|
10+
LL | #![deny(unused_parens)]
11+
| ^^^^^^^^^^^^^
12+
help: remove these parentheses
13+
|
14+
LL - for _ in (1..loop { break 2 }) {}
15+
LL + for _ in 1..loop { break 2 } {}
16+
|
17+
18+
error: unnecessary parentheses around `for` iterator expression
19+
--> $DIR/issue-90807-unused-paren-error.rs:8:14
20+
|
21+
LL | for _ in (1..match () { () => 2 }) {}
22+
| ^ ^
23+
|
24+
help: remove these parentheses
25+
|
26+
LL - for _ in (1..match () { () => 2 }) {}
27+
LL + for _ in 1..match () { () => 2 } {}
28+
|
29+
30+
error: aborting due to 2 previous errors
31+

0 commit comments

Comments
 (0)