Change:
I was changing some code from integer constants to a proper enum and was greeted by the following warning: The warning sounded weird to me because I was pattern-matching on that damn variant in various places of the code; but I was pointed out to the fact that I wasn't actually creating that value. Maybe the warning should be rewritten to explicitly mention value creation? Cc
cc that looks like your thing
duplicate of
Yup! Closing in favor of that.

Discussion:
id: ast::NodeId, span: syntax_pos::Span, name: ast::Name, <del> node_type: &str) { </del> <ins> node_type: &str, participle: &str) { </ins> if !name.as_str().starts_with("_") { self.tcx .lint_node(lint::builtin::DEAD_CODE, id, span, <del> &format!("{} is never used: `{}`", node_type, name)); </del> <ins> &format!("{} is never {}: `{}`", node_type, participle, name)); </ins> } } }

item.id, span, item.name, <del> item.node.descriptive_variant() </del> <ins> item.node.descriptive_variant(), "used", </ins> ); } else { // Only continue if we didn't warn

g: &'tcx hir::Generics, id: ast::NodeId) { if self.should_warn_about_variant(&variant.node) { <del> self.warn_dead_code(variant.node.data.id(), variant.span, variant.node.name, "variant"); </del> <ins> self.warn_dead_code(variant.node.data.id(), variant.span, variant.node.name, "variant", "constructed"); </ins> } else { intravisit::walk_variant(self, variant, g, id); }

fn visit_foreign_item(&mut self, fi: &'tcx hir::ForeignItem) { if self.should_warn_about_foreign_item(fi) { <del> self.warn_dead_code(fi.id, fi.span, fi.name, fi.node.descriptive_variant()); </del> <ins> self.warn_dead_code(fi.id, fi.span, fi.name, fi.node.descriptive_variant(), "used"); </ins> } intravisit::walk_foreign_item(self, fi); } fn visit_struct_field(&mut self, field: &'tcx hir::StructField) { if self.should_warn_about_field(&field) { <del> self.warn_dead_code(field.id, field.span, field.name, "field"); </del> <ins> self.warn_dead_code(field.id, field.span, field.name, "field", "used"); </ins> } intravisit::walk_struct_field(self, field); }

self.warn_dead_code(impl_item.id, impl_item.span, impl_item.name, <del> "associated const"); </del> <ins> "associated const", "used"); </ins> } 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); <del> self.warn_dead_code(impl_item.id, span, impl_item.name, "method"); </del> <ins> self.warn_dead_code(impl_item.id, span, impl_item.name, "method", "used"); </ins> } self.visit_nested_body(body_id) }

enum priv_enum { foo2, bar2 } //~ ERROR: enum is never used enum used_enum { foo3, <del> bar3 //~ ERROR variant is never used </del> <ins> bar3 //~ ERROR variant is never constructed </ins> } fn f<T>() {}

} enum XYZ { <del> X, //~ ERROR variant is never used Y { //~ ERROR variant is never used </del> <ins> X, //~ ERROR variant is never constructed Y { //~ ERROR variant is never constructed </ins> a: String, b: i32, c: i32,

// ensure struct variants get warning for their fields enum IJK { <del> I, //~ ERROR variant is never used </del> <ins> I, //~ ERROR variant is never constructed </ins> J { a: String, b: i32, //~ ERROR field is never used c: i32, //~ ERROR field is never used }, <del> K //~ ERROR variant is never used </del> <ins> K //~ ERROR variant is never constructed </ins> }

enum Enum1 { Variant1(isize), <del> Variant2 //~ ERROR: variant is never used </del> <ins> Variant2 //~ ERROR: variant is never constructed </ins> } enum Enum2 { Variant3(bool), #[allow(dead_code)] Variant4(isize), <del> Variant5 { _x: isize }, //~ ERROR: variant is never used: `Variant5` Variant6(isize), //~ ERROR: variant is never used: `Variant6` </del> <ins> Variant5 { _x: isize }, //~ ERROR: variant is never constructed: `Variant5` Variant6(isize), //~ ERROR: variant is never constructed: `Variant6` </ins> _Variant7, }

#[derive(Clone)] enum Enum { <del> Variant1, //~ ERROR: variant is never used </del> <ins> Variant1, //~ ERROR: variant is never constructed </ins> Variant2, }