Skip to content

Commit

Permalink
Rollup merge of #71026 - seiyab:issue-64362-adhoc, r=varkor
Browse files Browse the repository at this point in the history
Fix false "never constructed" warnings for `Self::` variant paths

Closes #64362 .
  • Loading branch information
Dylan-DPC authored Apr 19, 2020
2 parents 1b7dec9 + d3f8db6 commit 9c5da9a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/librustc_passes/dead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,9 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkSymbolVisitor<'a, 'tcx> {
hir::ExprKind::Field(ref lhs, ..) => {
self.handle_field_access(&lhs, expr.hir_id);
}
hir::ExprKind::Struct(_, ref fields, _) => {
hir::ExprKind::Struct(ref qpath, ref fields, _) => {
let res = self.tables.qpath_res(qpath, expr.hir_id);
self.handle_res(res);
if let ty::Adt(ref adt, _) = self.tables.expr_ty(expr).kind {
self.mark_as_used_if_union(adt, fields);
}
Expand Down
20 changes: 20 additions & 0 deletions src/test/ui/lint/dead-code/lint-dead-code-5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,23 @@ enum Enum2 {
Variant5 { _x: isize }, //~ ERROR: variant is never constructed: `Variant5`
Variant6(isize), //~ ERROR: variant is never constructed: `Variant6`
_Variant7,
Variant8 { _field: bool },
Variant9,
Variant10(usize)
}

impl Enum2 {
fn new_variant8() -> Enum2 {
Self::Variant8 { _field: true }
}

fn new_variant9() -> Enum2 {
Self::Variant9
}

fn new_variant10() -> Enum2 {
Self::Variant10(10)
}
}

enum Enum3 { //~ ERROR: enum is never used
Expand All @@ -27,4 +44,7 @@ fn main() {
Enum1::Variant2 => ()
}
let x = Enum2::Variant3(true);
let _ = Enum2::new_variant8();
let _ = Enum2::new_variant9();
let _ = Enum2::new_variant10();
}
2 changes: 1 addition & 1 deletion src/test/ui/lint/dead-code/lint-dead-code-5.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ LL | Variant6(isize),
| ^^^^^^^^^^^^^^^

error: enum is never used: `Enum3`
--> $DIR/lint-dead-code-5.rs:18:6
--> $DIR/lint-dead-code-5.rs:35:6
|
LL | enum Enum3 {
| ^^^^^
Expand Down

0 comments on commit 9c5da9a

Please sign in to comment.