Handle type aliases as well
This commit is contained in:
parent
09420fc206
commit
f94157eb61
@ -247,9 +247,12 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkSymbolVisitor<'a, 'tcx> {
|
||||
hir::ExprTupField(ref lhs, idx) => {
|
||||
self.handle_tup_field_access(&lhs, idx.node);
|
||||
}
|
||||
hir::ExprStruct(ref qpath, ref fields, _) => {
|
||||
let def = self.tables.qpath_def(qpath, expr.id);
|
||||
self.mark_as_used_if_union(def.def_id(), fields);
|
||||
hir::ExprStruct(_, ref fields, _) => {
|
||||
if let ty::TypeVariants::TyAdt(ref def, _) = self.tables.expr_ty(expr).sty {
|
||||
if def.is_union() {
|
||||
self.mark_as_used_if_union(def.did, fields);
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
|
@ -22,6 +22,13 @@ union U2 {
|
||||
}
|
||||
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() {
|
||||
let u = U1 { a: 0 };
|
||||
let _a = unsafe { u.b };
|
||||
@ -30,4 +37,6 @@ fn main() {
|
||||
let _b = unsafe { u.b };
|
||||
|
||||
let _u = NoDropLike { a: 10 };
|
||||
let u = A { a: 0 };
|
||||
let _b = unsafe { u.b };
|
||||
}
|
||||
|
@ -22,5 +22,11 @@ error: field is never used: `a`
|
||||
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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user