-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Emit warnings on unused parens/braces in index expressions
- Loading branch information
1 parent
dc1d9d5
commit c3a71ed
Showing
3 changed files
with
45 additions
and
0 deletions.
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,8 @@ | ||
#[deny(unused)] | ||
fn main() { | ||
let arr = [0; 10]; | ||
let _ = arr[(0)]; //~ ERROR unnecessary parentheses around index expression | ||
let _ = arr[{0}]; //~ ERROR unnecessary braces around index expression | ||
let _ = arr[1 + (0)]; | ||
let _ = arr[{ let x = 0; x }]; | ||
} |
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,33 @@ | ||
error: unnecessary parentheses around index expression | ||
--> $DIR/issue-96606.rs:4:17 | ||
| | ||
LL | let _ = arr[(0)]; | ||
| ^ ^ | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/issue-96606.rs:1:8 | ||
| | ||
LL | #[deny(unused)] | ||
| ^^^^^^ | ||
= note: `#[deny(unused_parens)]` implied by `#[deny(unused)]` | ||
help: remove these parentheses | ||
| | ||
LL - let _ = arr[(0)]; | ||
LL + let _ = arr[0]; | ||
| | ||
|
||
error: unnecessary braces around index expression | ||
--> $DIR/issue-96606.rs:5:17 | ||
| | ||
LL | let _ = arr[{0}]; | ||
| ^ ^ | ||
| | ||
= note: `#[deny(unused_braces)]` implied by `#[deny(unused)]` | ||
help: remove these braces | ||
| | ||
LL - let _ = arr[{0}]; | ||
LL + let _ = arr[0]; | ||
| | ||
|
||
error: aborting due to 2 previous errors | ||
|