Skip to content

Commit 5c5753e

Browse files
committed
Auto merge of #26500 - sanxiyn:dead-field, r=alexcrichton
Fix #26353.
2 parents 4e2a898 + 6f7b4ce commit 5c5753e

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/librustc/middle/dead.rs

+3
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
172172
};
173173
let fields = ty::lookup_struct_fields(self.tcx, id);
174174
for pat in pats {
175+
if let ast::PatWild(ast::PatWildSingle) = pat.node.pat.node {
176+
continue;
177+
}
175178
let field_id = fields.iter()
176179
.find(|field| field.name == pat.node.ident.name).unwrap().id;
177180
self.live_symbols.insert(field_id.node);

src/test/compile-fail/lint-dead-code-4.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,23 @@ enum XYZ {
2525
X, //~ ERROR variant is never used
2626
Y { //~ ERROR variant is never used
2727
a: String,
28-
b: isize //~ ERROR: struct field is never used
28+
b: i32, //~ ERROR: struct field is never used
29+
c: i32, //~ ERROR: struct field is never used
2930
},
3031
Z
3132
}
3233

3334
fn field_match_in_patterns(b: XYZ) -> String {
3435
match b {
35-
XYZ::Y { a, .. } => a,
36+
XYZ::Y { a, b: _, .. } => a,
3637
_ => "".to_string()
3738
}
3839
}
3940

4041
struct Bar {
4142
x: usize, //~ ERROR: struct field is never used
4243
b: bool,
44+
c: bool, //~ ERROR: struct field is never used
4345
_guard: ()
4446
}
4547

@@ -49,13 +51,13 @@ struct Baz {
4951
}
5052

5153
fn field_match_in_let(f: Bar) -> bool {
52-
let Bar { b, .. } = f;
54+
let Bar { b, c: _, .. } = f;
5355
b
5456
}
5557

5658
fn main() {
5759
field_read(Foo { x: 1, b: false });
5860
field_match_in_patterns(XYZ::Z);
59-
field_match_in_let(Bar { x: 42, b: true, _guard: () });
61+
field_match_in_let(Bar { x: 42, b: true, c: false, _guard: () });
6062
let _ = Baz { x: 0 };
6163
}

0 commit comments

Comments
 (0)