-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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 #82655 - SkiFire13:fix-issue-81314, r=estebank
Highlight identifier span instead of whole pattern span in `unused` lint Fixes #81314 This pretty much just changes the span highlighted in the lint from `pat_sp` to `ident.span`. There's however an exception, which is in patterns with shorthands like `Point { y, ref mut x }`, where a suggestion to change just `x` would be invalid; in those cases I had to keep the pattern span. Another option would be suggesting something like `Point { y, x: ref mut _x }`. I also added a new test since there weren't any test that checked the `unused` lint with optional patterns.
- Loading branch information
Showing
8 changed files
with
127 additions
and
59 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
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,12 @@ | ||
// run-rustfix | ||
// Regression test for #81314: Unused variable lint should | ||
// span only the identifier and not the rest of the pattern | ||
|
||
#![deny(unused)] | ||
|
||
fn main() { | ||
let [_rest @ ..] = [1, 2, 3]; //~ ERROR unused variable | ||
} | ||
|
||
pub fn foo([_rest @ ..]: &[i32]) { //~ ERROR unused variable | ||
} |
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,12 @@ | ||
// run-rustfix | ||
// Regression test for #81314: Unused variable lint should | ||
// span only the identifier and not the rest of the pattern | ||
|
||
#![deny(unused)] | ||
|
||
fn main() { | ||
let [rest @ ..] = [1, 2, 3]; //~ ERROR unused variable | ||
} | ||
|
||
pub fn foo([rest @ ..]: &[i32]) { //~ ERROR unused variable | ||
} |
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,21 @@ | ||
error: unused variable: `rest` | ||
--> $DIR/issue-81314-unused-span-ident.rs:8:10 | ||
| | ||
LL | let [rest @ ..] = [1, 2, 3]; | ||
| ^^^^ help: if this is intentional, prefix it with an underscore: `_rest` | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/issue-81314-unused-span-ident.rs:5:9 | ||
| | ||
LL | #![deny(unused)] | ||
| ^^^^^^ | ||
= note: `#[deny(unused_variables)]` implied by `#[deny(unused)]` | ||
|
||
error: unused variable: `rest` | ||
--> $DIR/issue-81314-unused-span-ident.rs:11:13 | ||
| | ||
LL | pub fn foo([rest @ ..]: &[i32]) { | ||
| ^^^^ help: if this is intentional, prefix it with an underscore: `_rest` | ||
|
||
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
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