Skip to content

Commit fe8438d

Browse files
committed
Fix "field is never used" warning to take unions into account
Rather than saying "struct or union" or adding logic to determine the type of the item, just change the message to "field is never used", dropping the "struct". Update tests accordingly.
1 parent d748fa6 commit fe8438d

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/librustc/middle/dead.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for DeadVisitor<'a, 'tcx> {
548548
fn visit_struct_field(&mut self, field: &hir::StructField) {
549549
if self.should_warn_about_field(&field) {
550550
self.warn_dead_code(field.id, field.span,
551-
field.name, "struct field");
551+
field.name, "field");
552552
}
553553

554554
intravisit::walk_struct_field(self, field);

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
struct Foo {
1616
x: usize,
17-
b: bool, //~ ERROR: struct field is never used
17+
b: bool, //~ ERROR: field is never used
1818
}
1919

2020
fn field_read(f: Foo) -> usize {
@@ -46,8 +46,8 @@ enum IJK {
4646
I, //~ ERROR variant is never used
4747
J {
4848
a: String,
49-
b: i32, //~ ERROR struct field is never used
50-
c: i32, //~ ERROR struct field is never used
49+
b: i32, //~ ERROR field is never used
50+
c: i32, //~ ERROR field is never used
5151
},
5252
K //~ ERROR variant is never used
5353

@@ -68,9 +68,9 @@ fn field_match_in_patterns(b: XYZ) -> String {
6868
}
6969

7070
struct Bar {
71-
x: usize, //~ ERROR: struct field is never used
71+
x: usize, //~ ERROR: field is never used
7272
b: bool,
73-
c: bool, //~ ERROR: struct field is never used
73+
c: bool, //~ ERROR: field is never used
7474
_guard: ()
7575
}
7676

0 commit comments

Comments
 (0)