File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed 
compiler/rustc_passes/src Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -125,9 +125,13 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
125125 )  => { 
126126 self . check_def_id ( def_id) ; 
127127 } 
128-  _ if  self . in_pat  => { } 
129128 Res :: PrimTy ( ..)  | Res :: SelfCtor ( ..)  | Res :: Local ( ..)  => { } 
130129 Res :: Def ( DefKind :: Ctor ( CtorOf :: Variant ,  ..) ,  ctor_def_id)  => { 
130+  // Using a variant in patterns should not make the variant live, 
131+  // since we can just remove the match arm that matches the pattern 
132+  if  self . in_pat  { 
133+  return ; 
134+  } 
131135 let  variant_id = self . tcx . parent ( ctor_def_id) ; 
132136 let  enum_id = self . tcx . parent ( variant_id) ; 
133137 self . check_def_id ( enum_id) ; 
@@ -136,6 +140,11 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
136140 } 
137141 } 
138142 Res :: Def ( DefKind :: Variant ,  variant_id)  => { 
143+  // Using a variant in patterns should not make the variant live, 
144+  // since we can just remove the match arm that matches the pattern 
145+  if  self . in_pat  { 
146+  return ; 
147+  } 
139148 let  enum_id = self . tcx . parent ( variant_id) ; 
140149 self . check_def_id ( enum_id) ; 
141150 if  !self . ignore_variant_stack . contains ( & variant_id)  { 
Original file line number Diff line number Diff line change 1+ //@ check-pass 
2+ 
3+ #![ deny( dead_code) ]  
4+ 
5+ #[ derive( Default ) ]  
6+ struct  Test  { 
7+ 
8+ } 
9+ 
10+ fn  main ( )  { 
11+  if  let  Some :: < Test > ( test)  = magic :: < Test > ( )  { 
12+ 
13+  } 
14+ } 
15+ 
16+ 
17+ fn  magic < T :  Default > ( )  -> Option < T >  { 
18+  Some ( T :: default ( ) ) 
19+ } 
                         You can’t perform that action at this time. 
           
                  
0 commit comments