-
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.
concerning well-formed suggestions for unused shorthand field patterns
Previously, unused variables would get a note that the warning could be silenced by prefixing the variable with an underscore, but that doesn't work for field shorthand patterns, which the liveness analysis didn't know about. The "to avoid this warning" verbiage seemed unnecessary. Resolves #47390.
- Loading branch information
1 parent
8f9d915
commit e4b1a79
Showing
4 changed files
with
124 additions
and
16 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
34 changes: 34 additions & 0 deletions
34
src/test/ui/lint/issue-47390-unused-variable-in-struct-pattern.rs
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,34 @@ | ||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// must-compile-successfully | ||
|
||
#![warn(unused)] // UI tests pass `-A unused` (#43896) | ||
|
||
struct SoulHistory { | ||
corridors_of_light: usize, | ||
hours_are_suns: bool, | ||
endless_and_singing: bool | ||
} | ||
|
||
fn main() { | ||
let i_think_continually = 2; | ||
let who_from_the_womb_remembered = SoulHistory { | ||
corridors_of_light: 5, | ||
hours_are_suns: true, | ||
endless_and_singing: true | ||
}; | ||
|
||
if let SoulHistory { corridors_of_light, | ||
mut hours_are_suns, | ||
endless_and_singing: true } = who_from_the_womb_remembered { | ||
hours_are_suns = false; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
warning: unused variable: `i_think_continually` | ||
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:22:9 | ||
| | ||
22 | 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 | ||
| | ||
13 | #![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 | ||
| | ||
29 | 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 | ||
| | ||
30 | 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 | ||
| | ||
32 | hours_are_suns = false; | ||
| ^^^^^^^^^^^^^^ | ||
| | ||
note: lint level defined here | ||
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:13:9 | ||
| | ||
13 | #![warn(unused)] // UI tests pass `-A unused` (#43896) | ||
| ^^^^^^ | ||
= note: #[warn(unused_assignments)] implied by #[warn(unused)] | ||
|
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
Oops, this is slightly ironic for a commit specifically about struct field shorthand ... 😞