forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#91956 - notriddle:notriddle/unused-parens-r…
…ange, r=nagisa fix(rustc_lint): better detect when parens are necessary Fixes rust-lang#90807
- Loading branch information
Showing
4 changed files
with
52 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Make sure unused parens lint emit is emitted for loop and match. | ||
// See https://github.com/rust-lang/rust/issues/90807 | ||
// and https://github.com/rust-lang/rust/pull/91956#discussion_r771647953 | ||
#![deny(unused_parens)] | ||
|
||
fn main() { | ||
for _ in (1..loop { break 2 }) {} //~ERROR | ||
for _ in (1..match () { () => 2 }) {} //~ERROR | ||
} |
31 changes: 31 additions & 0 deletions
31
src/test/ui/lint/unused/issue-90807-unused-paren-error.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
error: unnecessary parentheses around `for` iterator expression | ||
--> $DIR/issue-90807-unused-paren-error.rs:7:14 | ||
| | ||
LL | for _ in (1..loop { break 2 }) {} | ||
| ^ ^ | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/issue-90807-unused-paren-error.rs:4:9 | ||
| | ||
LL | #![deny(unused_parens)] | ||
| ^^^^^^^^^^^^^ | ||
help: remove these parentheses | ||
| | ||
LL - for _ in (1..loop { break 2 }) {} | ||
LL + for _ in 1..loop { break 2 } {} | ||
| | ||
|
||
error: unnecessary parentheses around `for` iterator expression | ||
--> $DIR/issue-90807-unused-paren-error.rs:8:14 | ||
| | ||
LL | for _ in (1..match () { () => 2 }) {} | ||
| ^ ^ | ||
| | ||
help: remove these parentheses | ||
| | ||
LL - for _ in (1..match () { () => 2 }) {} | ||
LL + for _ in 1..match () { () => 2 } {} | ||
| | ||
|
||
error: aborting due to 2 previous errors | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 }) {} | ||
} |