Change:
A "variant is never used" lint is incorrectly triggered, presumably due to optimizations on MIR. I know my code sample looks pretty stupid as no human would write this, probably. But this kind of code might be generated. Anyway, the lint is incorrect I'd say. I tried this code: I expected to see this happen: no warning Instead, this happened: Happens with 1.19 stable, 1.20 beta, 1.21 nightly
Just to be clear: isn't considered unused because the arm is not reached. It's considered unused because the variant is never constructed. If the variant is never constructed, it doesn't make any difference whether matches are prepared to handle it (and besides, those matches will never be executed -- by analogy, we also consider functions unused if they're called from other dead code only).
Oh right. Then I guess this can be closed, since it's a dupe of

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, }