diff --git a/src/librustc/middle/dead.rs b/src/librustc/middle/dead.rs index a42ff543227a8..21eb772b1b376 100644 --- a/src/librustc/middle/dead.rs +++ b/src/librustc/middle/dead.rs @@ -531,13 +531,15 @@ impl<'a, 'tcx> DeadVisitor<'a, 'tcx> { id: ast::NodeId, span: syntax_pos::Span, name: ast::Name, - node_type: &str) { + node_type: &str, + participle: &str) { if !name.as_str().starts_with("_") { self.tcx .lint_node(lint::builtin::DEAD_CODE, id, span, - &format!("{} is never used: `{}`", node_type, name)); + &format!("{} is never {}: `{}`", + node_type, participle, name)); } } } @@ -570,7 +572,8 @@ impl<'a, 'tcx> Visitor<'tcx> for DeadVisitor<'a, 'tcx> { item.id, span, item.name, - item.node.descriptive_variant() + item.node.descriptive_variant(), + "used", ); } else { // Only continue if we didn't warn @@ -583,7 +586,8 @@ impl<'a, 'tcx> Visitor<'tcx> for DeadVisitor<'a, 'tcx> { g: &'tcx hir::Generics, id: ast::NodeId) { if self.should_warn_about_variant(&variant.node) { - self.warn_dead_code(variant.node.data.id(), variant.span, variant.node.name, "variant"); + self.warn_dead_code(variant.node.data.id(), variant.span, variant.node.name, + "variant", "constructed"); } else { intravisit::walk_variant(self, variant, g, id); } @@ -591,15 +595,15 @@ impl<'a, 'tcx> Visitor<'tcx> for DeadVisitor<'a, 'tcx> { fn visit_foreign_item(&mut self, fi: &'tcx hir::ForeignItem) { if self.should_warn_about_foreign_item(fi) { - self.warn_dead_code(fi.id, fi.span, fi.name, fi.node.descriptive_variant()); + self.warn_dead_code(fi.id, fi.span, fi.name, + fi.node.descriptive_variant(), "used"); } intravisit::walk_foreign_item(self, fi); } fn visit_struct_field(&mut self, field: &'tcx hir::StructField) { if self.should_warn_about_field(&field) { - self.warn_dead_code(field.id, field.span, - field.name, "field"); + self.warn_dead_code(field.id, field.span, field.name, "field", "used"); } intravisit::walk_struct_field(self, field); } @@ -611,14 +615,15 @@ impl<'a, 'tcx> Visitor<'tcx> for DeadVisitor<'a, 'tcx> { self.warn_dead_code(impl_item.id, impl_item.span, impl_item.name, - "associated const"); + "associated const", + "used"); } self.visit_nested_body(body_id) } hir::ImplItemKind::Method(_, body_id) => { if !self.symbol_is_live(impl_item.id, None) { let span = self.tcx.sess.codemap().def_span(impl_item.span); - self.warn_dead_code(impl_item.id, span, impl_item.name, "method"); + self.warn_dead_code(impl_item.id, span, impl_item.name, "method", "used"); } self.visit_nested_body(body_id) } diff --git a/src/test/compile-fail/lint-dead-code-1.rs b/src/test/compile-fail/lint-dead-code-1.rs index f45e80f5252e3..d6ca5e6b1d969 100644 --- a/src/test/compile-fail/lint-dead-code-1.rs +++ b/src/test/compile-fail/lint-dead-code-1.rs @@ -74,7 +74,7 @@ pub enum pub_enum3 { enum priv_enum { foo2, bar2 } //~ ERROR: enum is never used enum used_enum { foo3, - bar3 //~ ERROR variant is never used + bar3 //~ ERROR variant is never constructed } fn f() {} diff --git a/src/test/compile-fail/lint-dead-code-4.rs b/src/test/compile-fail/lint-dead-code-4.rs index 3df089fc20048..1296cf46e6fe4 100644 --- a/src/test/compile-fail/lint-dead-code-4.rs +++ b/src/test/compile-fail/lint-dead-code-4.rs @@ -22,8 +22,8 @@ fn field_read(f: Foo) -> usize { } enum XYZ { - X, //~ ERROR variant is never used - Y { //~ ERROR variant is never used + X, //~ ERROR variant is never constructed + Y { //~ ERROR variant is never constructed a: String, b: i32, c: i32, @@ -43,13 +43,13 @@ enum ABC { //~ ERROR enum is never used // ensure struct variants get warning for their fields enum IJK { - I, //~ ERROR variant is never used + I, //~ ERROR variant is never constructed J { a: String, b: i32, //~ ERROR field is never used c: i32, //~ ERROR field is never used }, - K //~ ERROR variant is never used + K //~ ERROR variant is never constructed } diff --git a/src/test/compile-fail/lint-dead-code-5.rs b/src/test/compile-fail/lint-dead-code-5.rs index 04d6547d93812..ee5cf24823d40 100644 --- a/src/test/compile-fail/lint-dead-code-5.rs +++ b/src/test/compile-fail/lint-dead-code-5.rs @@ -13,15 +13,15 @@ enum Enum1 { Variant1(isize), - Variant2 //~ ERROR: variant is never used + Variant2 //~ ERROR: variant is never constructed } enum Enum2 { Variant3(bool), #[allow(dead_code)] Variant4(isize), - Variant5 { _x: isize }, //~ ERROR: variant is never used: `Variant5` - Variant6(isize), //~ ERROR: variant is never used: `Variant6` + Variant5 { _x: isize }, //~ ERROR: variant is never constructed: `Variant5` + Variant6(isize), //~ ERROR: variant is never constructed: `Variant6` _Variant7, } diff --git a/src/test/compile-fail/lint-dead-code-variant.rs b/src/test/compile-fail/lint-dead-code-variant.rs index 0116d63caf230..3301560c31500 100644 --- a/src/test/compile-fail/lint-dead-code-variant.rs +++ b/src/test/compile-fail/lint-dead-code-variant.rs @@ -12,7 +12,7 @@ #[derive(Clone)] enum Enum { - Variant1, //~ ERROR: variant is never used + Variant1, //~ ERROR: variant is never constructed Variant2, }