Correct unused field warning on &struct match
This commit is contained in:
parent
a9975254ee
commit
cc53db8bf9
3 changed files with 41 additions and 13 deletions
|
@ -412,18 +412,28 @@ fn visit_local<'a, 'tcx>(ir: &mut IrMaps<'a, 'tcx>, local: &'tcx hir::Local) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_arm<'a, 'tcx>(ir: &mut IrMaps<'a, 'tcx>, arm: &'tcx hir::Arm) {
|
fn visit_arm<'a, 'tcx>(ir: &mut IrMaps<'a, 'tcx>, arm: &'tcx hir::Arm) {
|
||||||
for pat in &arm.pats {
|
for mut pat in &arm.pats {
|
||||||
// for struct patterns, take note of which fields used shorthand (`x` rather than `x: x`)
|
// For struct patterns, take note of which fields used shorthand
|
||||||
|
// (`x` rather than `x: x`).
|
||||||
//
|
//
|
||||||
// FIXME: according to the rust-lang-nursery/rustc-guide book, `NodeId`s are to be phased
|
// FIXME: according to the rust-lang-nursery/rustc-guide book, `NodeId`s are to be
|
||||||
// out in favor of `HirId`s; however, we need to match the signature of `each_binding`,
|
// phased out in favor of `HirId`s; however, we need to match the signature of
|
||||||
// which uses `NodeIds`.
|
// `each_binding`, which uses `NodeIds`.
|
||||||
let mut shorthand_field_ids = NodeSet();
|
let mut shorthand_field_ids = NodeSet();
|
||||||
if let hir::PatKind::Struct(_, ref fields, _) = pat.node {
|
loop {
|
||||||
for field in fields {
|
match pat.node {
|
||||||
if field.node.is_shorthand {
|
hir::PatKind::Struct(_, ref fields, _) => {
|
||||||
shorthand_field_ids.insert(field.node.pat.id);
|
for field in fields {
|
||||||
|
if field.node.is_shorthand {
|
||||||
|
shorthand_field_ids.insert(field.node.pat.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
hir::PatKind::Ref(ref deref_pat, _) => {
|
||||||
|
pat = deref_pat;
|
||||||
|
}
|
||||||
|
_ => break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,10 @@ struct SoulHistory {
|
||||||
endless_and_singing: bool
|
endless_and_singing: bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum Large {
|
||||||
|
Suit { case: () }
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let i_think_continually = 2;
|
let i_think_continually = 2;
|
||||||
let who_from_the_womb_remembered = SoulHistory {
|
let who_from_the_womb_remembered = SoulHistory {
|
||||||
|
@ -31,4 +35,12 @@ fn main() {
|
||||||
endless_and_singing: true } = who_from_the_womb_remembered {
|
endless_and_singing: true } = who_from_the_womb_remembered {
|
||||||
hours_are_suns = false;
|
hours_are_suns = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let bag = &Large::Suit {
|
||||||
|
case: ()
|
||||||
|
};
|
||||||
|
|
||||||
|
match bag {
|
||||||
|
&Large::Suit { case } => {}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
warning: unused variable: `i_think_continually`
|
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:26:9
|
||||||
|
|
|
|
||||||
LL | let i_think_continually = 2;
|
LL | let i_think_continually = 2;
|
||||||
| ^^^^^^^^^^^^^^^^^^^ help: consider using `_i_think_continually` instead
|
| ^^^^^^^^^^^^^^^^^^^ help: consider using `_i_think_continually` instead
|
||||||
|
@ -12,13 +12,13 @@ LL | #![warn(unused)] // UI tests pass `-A unused` (#43896)
|
||||||
= note: #[warn(unused_variables)] implied by #[warn(unused)]
|
= note: #[warn(unused_variables)] implied by #[warn(unused)]
|
||||||
|
|
||||||
warning: unused variable: `corridors_of_light`
|
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:33:26
|
||||||
|
|
|
|
||||||
LL | if let SoulHistory { corridors_of_light,
|
LL | if let SoulHistory { corridors_of_light,
|
||||||
| ^^^^^^^^^^^^^^^^^^ help: try ignoring the field: `corridors_of_light: _`
|
| ^^^^^^^^^^^^^^^^^^ help: try ignoring the field: `corridors_of_light: _`
|
||||||
|
|
||||||
warning: variable `hours_are_suns` is assigned to, but never used
|
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:34:26
|
||||||
|
|
|
|
||||||
LL | mut hours_are_suns,
|
LL | mut hours_are_suns,
|
||||||
| ^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^
|
||||||
|
@ -26,7 +26,7 @@ LL | mut hours_are_suns,
|
||||||
= note: consider using `_hours_are_suns` instead
|
= note: consider using `_hours_are_suns` instead
|
||||||
|
|
||||||
warning: value assigned to `hours_are_suns` is never read
|
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:36:9
|
||||||
|
|
|
|
||||||
LL | hours_are_suns = false;
|
LL | hours_are_suns = false;
|
||||||
| ^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^
|
||||||
|
@ -38,3 +38,9 @@ LL | #![warn(unused)] // UI tests pass `-A unused` (#43896)
|
||||||
| ^^^^^^
|
| ^^^^^^
|
||||||
= note: #[warn(unused_assignments)] implied by #[warn(unused)]
|
= note: #[warn(unused_assignments)] implied by #[warn(unused)]
|
||||||
|
|
||||||
|
warning: unused variable: `case`
|
||||||
|
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:44:24
|
||||||
|
|
|
||||||
|
LL | &Large::Suit { case } => {}
|
||||||
|
| ^^^^ help: try ignoring the field: `case: _`
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue