Handle type aliases as well

This commit is contained in:
Guillaume Gomez 2017-08-06 20:46:32 +02:00
parent 09420fc206
commit f94157eb61
3 changed files with 22 additions and 4 deletions

View File

@ -247,9 +247,12 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkSymbolVisitor<'a, 'tcx> {
hir::ExprTupField(ref lhs, idx) => { hir::ExprTupField(ref lhs, idx) => {
self.handle_tup_field_access(&lhs, idx.node); self.handle_tup_field_access(&lhs, idx.node);
} }
hir::ExprStruct(ref qpath, ref fields, _) => { hir::ExprStruct(_, ref fields, _) => {
let def = self.tables.qpath_def(qpath, expr.id); if let ty::TypeVariants::TyAdt(ref def, _) = self.tables.expr_ty(expr).sty {
self.mark_as_used_if_union(def.def_id(), fields); if def.is_union() {
self.mark_as_used_if_union(def.did, fields);
}
}
} }
_ => () _ => ()
} }

View File

@ -22,6 +22,13 @@ union U2 {
} }
union NoDropLike { a: u8 } // should be reported as unused union NoDropLike { a: u8 } // should be reported as unused
union U {
a: u8, // should not be reported
b: u8, // should not be reported
c: u8, // should be reported
}
type A = U;
fn main() { fn main() {
let u = U1 { a: 0 }; let u = U1 { a: 0 };
let _a = unsafe { u.b }; let _a = unsafe { u.b };
@ -30,4 +37,6 @@ fn main() {
let _b = unsafe { u.b }; let _b = unsafe { u.b };
let _u = NoDropLike { a: 10 }; let _u = NoDropLike { a: 10 };
let u = A { a: 0 };
let _b = unsafe { u.b };
} }

View File

@ -22,5 +22,11 @@ error: field is never used: `a`
23 | union NoDropLike { a: u8 } // should be reported as unused 23 | union NoDropLike { a: u8 } // should be reported as unused
| ^^^^^ | ^^^^^
error: aborting due to 3 previous errors error: field is never used: `c`
--> $DIR/union-fields.rs:28:5
|
28 | c: u8, // should be reported
| ^^^^^
error: aborting due to 4 previous errors