forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
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#107539 - PossiblyAShrub:unused-parens-in-in…
…dex, r=lcnr Emit warnings on unused parens in index expressions Fixes: rust-lang#96606. I am not sure what the best term for "index expression" is. Is there a better term we could use?
- Loading branch information
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 | ||
|