Skip to content

Commit

Permalink
Fix false "never constructed" warnings for Self:: variant paths
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubadamw committed Sep 13, 2019
1 parent fe6d05a commit 10ed1f1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
16 changes: 5 additions & 11 deletions src/librustc/middle/dead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,6 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkSymbolVisitor<'a, 'tcx> {

fn visit_expr(&mut self, expr: &'tcx hir::Expr) {
match expr.node {
hir::ExprKind::Path(ref qpath @ hir::QPath::TypeRelative(..)) => {
let res = self.tables.qpath_res(qpath, expr.hir_id);
self.handle_res(res);
}
hir::ExprKind::MethodCall(..) => {
self.lookup_and_handle_method(expr.hir_id);
}
Expand Down Expand Up @@ -280,10 +276,6 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkSymbolVisitor<'a, 'tcx> {
let res = self.tables.qpath_res(path, pat.hir_id);
self.handle_field_pattern_match(pat, res, fields);
}
PatKind::Path(ref qpath) => {
let res = self.tables.qpath_res(qpath, pat.hir_id);
self.handle_res(res);
}
_ => ()
}

Expand All @@ -292,9 +284,11 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkSymbolVisitor<'a, 'tcx> {
self.in_pat = false;
}

fn visit_path(&mut self, path: &'tcx hir::Path, _: hir::HirId) {
self.handle_res(path.res);
intravisit::walk_path(self, path);
fn visit_qpath(&mut self, qpath: &'tcx hir::QPath,
id: hir::HirId, span: syntax_pos::Span) {
let res = self.tables.qpath_res(qpath, id);
self.handle_res(res);
intravisit::walk_qpath(self, qpath, id, span);
}

fn visit_ty(&mut self, ty: &'tcx hir::Ty) {
Expand Down
22 changes: 21 additions & 1 deletion src/test/ui/lint/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 @@ -26,5 +43,8 @@ fn main() {
Enum1::Variant1(_) => (),
Enum1::Variant2 => ()
}
let x = Enum2::Variant3(true);
let _ = 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/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:1
--> $DIR/lint-dead-code-5.rs:35:1
|
LL | enum Enum3 {
| ^^^^^^^^^^
Expand Down

0 comments on commit 10ed1f1

Please sign in to comment.