-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve "try ignoring the field" diagnostic
Closes #95795
- Loading branch information
1 parent
f03ce30
commit 3fb249b
Showing
5 changed files
with
88 additions
and
2 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,17 @@ | ||
// run-pass | ||
|
||
#![allow(dead_code)] | ||
|
||
struct Foo { | ||
foo: i32, | ||
bar: i32, | ||
baz: (), | ||
} | ||
|
||
fn use_foo(x: Foo) -> (i32, i32) { | ||
let Foo { foo, bar, baz } = x; //~ WARNING unused variable: `baz` | ||
//~| help: try ignoring the field | ||
return (foo, bar); | ||
} | ||
|
||
fn main() {} |
10 changes: 10 additions & 0 deletions
10
src/test/ui/suggestions/dont-try-removing-the-field.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,10 @@ | ||
warning: unused variable: `baz` | ||
--> $DIR/dont-try-removing-the-field.rs:12:25 | ||
| | ||
LL | let Foo { foo, bar, baz } = x; | ||
| ^^^ help: try ignoring the field: `baz: _` | ||
| | ||
= note: `#[warn(unused_variables)]` on by default | ||
|
||
warning: 1 warning emitted | ||
|
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,17 @@ | ||
// run-pass | ||
|
||
#![allow(dead_code)] | ||
|
||
struct Foo { | ||
foo: i32, | ||
bar: (), | ||
baz: (), | ||
} | ||
|
||
fn use_foo(x: Foo) -> i32 { | ||
let Foo { foo, bar, .. } = x; //~ WARNING unused variable: `bar` | ||
//~| help: try removing the field | ||
return foo; | ||
} | ||
|
||
fn main() {} |
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 @@ | ||
warning: unused variable: `bar` | ||
--> $DIR/try-removing-the-field.rs:12:20 | ||
| | ||
LL | let Foo { foo, bar, .. } = x; | ||
| ^^^- | ||
| | | ||
| help: try removing the field | ||
| | ||
= note: `#[warn(unused_variables)]` on by default | ||
|
||
warning: 1 warning emitted | ||
|