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#50327 - varkor:match-unused-struct-field, r…
…=estebank Display correct unused field suggestion for nested struct patterns Extends rust-lang#47922 by checking more sophisticated patterns (e.g. references, slices, etc.). Before: ``` warning: unused variable: `bar` --> src/main.rs:37:21 | 37 | &Foo::Bar { bar } => true, | ^^^ help: consider using `_bar` instead | = note: #[warn(unused_variables)] on by default ``` After: ``` warning: unused variable: `bar` --> src/main.rs:37:21 | 37 | &Foo::Bar { bar } => true, | ^^^ help: try ignoring the field: `bar: _` | = note: #[warn(unused_variables)] on by default ``` Fixes rust-lang#50303. r? @estebank
- Loading branch information
Showing
3 changed files
with
120 additions
and
15 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
48 changes: 42 additions & 6 deletions
48
src/test/ui/lint/issue-47390-unused-variable-in-struct-pattern.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 |
---|---|---|
@@ -1,40 +1,76 @@ | ||
warning: unused variable: `i_think_continually` | ||
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:22:9 | ||
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:31:9 | ||
| | ||
LL | let i_think_continually = 2; | ||
| ^^^^^^^^^^^^^^^^^^^ help: consider using `_i_think_continually` instead | ||
| | ||
note: lint level defined here | ||
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:13:9 | ||
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:15:9 | ||
| | ||
LL | #![warn(unused)] // UI tests pass `-A unused` (#43896) | ||
| ^^^^^^ | ||
= note: #[warn(unused_variables)] implied by #[warn(unused)] | ||
|
||
warning: unused variable: `corridors_of_light` | ||
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:29:26 | ||
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:38:26 | ||
| | ||
LL | if let SoulHistory { corridors_of_light, | ||
| ^^^^^^^^^^^^^^^^^^ help: try ignoring the field: `corridors_of_light: _` | ||
|
||
warning: variable `hours_are_suns` is assigned to, but never used | ||
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:30:26 | ||
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:39:26 | ||
| | ||
LL | mut hours_are_suns, | ||
| ^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: consider using `_hours_are_suns` instead | ||
|
||
warning: value assigned to `hours_are_suns` is never read | ||
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:32:9 | ||
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:41:9 | ||
| | ||
LL | hours_are_suns = false; | ||
| ^^^^^^^^^^^^^^ | ||
| | ||
note: lint level defined here | ||
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:13:9 | ||
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:15:9 | ||
| | ||
LL | #![warn(unused)] // UI tests pass `-A unused` (#43896) | ||
| ^^^^^^ | ||
= note: #[warn(unused_assignments)] implied by #[warn(unused)] | ||
|
||
warning: unused variable: `case` | ||
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:50:23 | ||
| | ||
LL | Large::Suit { case } => {} | ||
| ^^^^ help: try ignoring the field: `case: _` | ||
|
||
warning: unused variable: `case` | ||
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:55:24 | ||
| | ||
LL | &Large::Suit { case } => {} | ||
| ^^^^ help: try ignoring the field: `case: _` | ||
|
||
warning: unused variable: `case` | ||
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:60:27 | ||
| | ||
LL | box Large::Suit { case } => {} | ||
| ^^^^ help: try ignoring the field: `case: _` | ||
|
||
warning: unused variable: `case` | ||
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:65:24 | ||
| | ||
LL | (Large::Suit { case },) => {} | ||
| ^^^^ help: try ignoring the field: `case: _` | ||
|
||
warning: unused variable: `case` | ||
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:70:24 | ||
| | ||
LL | [Large::Suit { case }] => {} | ||
| ^^^^ help: try ignoring the field: `case: _` | ||
|
||
warning: unused variable: `case` | ||
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:75:29 | ||
| | ||
LL | Tuple(Large::Suit { case }, ()) => {} | ||
| ^^^^ help: try ignoring the field: `case: _` | ||
|