Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion compiler/rustc_passes/src/dead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,13 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
) => {
self.check_def_id(def_id);
}
_ if self.in_pat => {}
Res::PrimTy(..) | Res::SelfCtor(..) | Res::Local(..) => {}
Res::Def(DefKind::Ctor(CtorOf::Variant, ..), ctor_def_id) => {
// Using a variant in patterns should not make the variant live,
// since we can just remove the match arm that matches the pattern
if self.in_pat {
return;
}
let variant_id = self.tcx.parent(ctor_def_id);
let enum_id = self.tcx.parent(variant_id);
self.check_def_id(enum_id);
Expand All @@ -136,6 +140,11 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
}
}
Res::Def(DefKind::Variant, variant_id) => {
// Using a variant in patterns should not make the variant live,
// since we can just remove the match arm that matches the pattern
if self.in_pat {
return;
}
let enum_id = self.tcx.parent(variant_id);
self.check_def_id(enum_id);
if !self.ignore_variant_stack.contains(&variant_id) {
Expand Down
16 changes: 16 additions & 0 deletions tests/ui/lint/dead-code/inferred-generic-arg.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//@ check-pass

#![deny(dead_code)]

#[derive(Default)]
struct Test {

}

fn main() {
if let Some::<Test>(test) = magic::<Test>() { }
}

fn magic<T: Default>() -> Option<T> {
Some(T::default())
}
Loading