-
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.
Rollup merge of #88871 - FabianWolff:issue-88403, r=jackh726
Fix suggestion for nested struct patterns Fixes #88403, and also a similar problem where the unused binding is in a function parameter pattern.
- Loading branch information
Showing
4 changed files
with
75 additions
and
8 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,20 @@ | ||
// Regression test for #88403, where prefixing with an underscore was | ||
// erroneously suggested for a nested shorthand struct field binding. | ||
|
||
// run-rustfix | ||
#![allow(unused)] | ||
#![forbid(unused_variables)] | ||
|
||
struct Inner { i: i32 } | ||
struct Outer { o: Inner } | ||
|
||
fn foo(Outer { o: Inner { i: _ } }: Outer) {} | ||
//~^ ERROR: unused variable: `i` | ||
//~| HELP: try ignoring the field | ||
|
||
fn main() { | ||
let s = Outer { o: Inner { i: 42 } }; | ||
let Outer { o: Inner { i: _ } } = s; | ||
//~^ ERROR: unused variable: `i` | ||
//~| HELP: try ignoring the field | ||
} |
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,20 @@ | ||
// Regression test for #88403, where prefixing with an underscore was | ||
// erroneously suggested for a nested shorthand struct field binding. | ||
|
||
// run-rustfix | ||
#![allow(unused)] | ||
#![forbid(unused_variables)] | ||
|
||
struct Inner { i: i32 } | ||
struct Outer { o: Inner } | ||
|
||
fn foo(Outer { o: Inner { i } }: Outer) {} | ||
//~^ ERROR: unused variable: `i` | ||
//~| HELP: try ignoring the field | ||
|
||
fn main() { | ||
let s = Outer { o: Inner { i: 42 } }; | ||
let Outer { o: Inner { i } } = s; | ||
//~^ ERROR: unused variable: `i` | ||
//~| HELP: try ignoring the field | ||
} |
20 changes: 20 additions & 0 deletions
20
src/test/ui/suggestions/ignore-nested-field-binding.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,20 @@ | ||
error: unused variable: `i` | ||
--> $DIR/ignore-nested-field-binding.rs:11:27 | ||
| | ||
LL | fn foo(Outer { o: Inner { i } }: Outer) {} | ||
| ^ help: try ignoring the field: `i: _` | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/ignore-nested-field-binding.rs:6:11 | ||
| | ||
LL | #![forbid(unused_variables)] | ||
| ^^^^^^^^^^^^^^^^ | ||
|
||
error: unused variable: `i` | ||
--> $DIR/ignore-nested-field-binding.rs:17:28 | ||
| | ||
LL | let Outer { o: Inner { i } } = s; | ||
| ^ help: try ignoring the field: `i: _` | ||
|
||
error: aborting due to 2 previous errors | ||
|