@@ -391,13 +391,13 @@ impl<'p, 'tcx> PatStack<'p, 'tcx> {
391391 & self ,
392392 cx : & mut MatchCheckCtxt < ' a , ' tcx > ,
393393 constructor : & Constructor < ' tcx > ,
394- wild_patterns : & [ & ' q Pat < ' tcx > ] ,
394+ ctor_wild_subpatterns : & [ & ' q Pat < ' tcx > ] ,
395395 ) -> Option < PatStack < ' q , ' tcx > >
396396 where
397397 ' a : ' q ,
398398 ' p : ' q ,
399399 {
400- specialize ( cx, self , constructor, wild_patterns )
400+ specialize ( cx, self , constructor, ctor_wild_subpatterns )
401401 }
402402}
403403
@@ -443,7 +443,7 @@ impl<'p, 'tcx> Matrix<'p, 'tcx> {
443443 & self ,
444444 cx : & mut MatchCheckCtxt < ' a , ' tcx > ,
445445 constructor : & Constructor < ' tcx > ,
446- wild_patterns : & [ & ' q Pat < ' tcx > ] ,
446+ ctor_wild_subpatterns : & [ & ' q Pat < ' tcx > ] ,
447447 ) -> Matrix < ' q , ' tcx >
448448 where
449449 ' a : ' q ,
@@ -452,7 +452,7 @@ impl<'p, 'tcx> Matrix<'p, 'tcx> {
452452 Matrix (
453453 self . 0
454454 . iter ( )
455- . filter_map ( |r| r. specialize_constructor ( cx, constructor, wild_patterns ) )
455+ . filter_map ( |r| r. specialize_constructor ( cx, constructor, ctor_wild_subpatterns ) )
456456 . collect ( ) ,
457457 )
458458 }
@@ -1340,7 +1340,7 @@ pub fn is_useful<'p, 'a, 'tcx>(
13401340 cx : & mut MatchCheckCtxt < ' a , ' tcx > ,
13411341 matrix : & Matrix < ' p , ' tcx > ,
13421342 v : & PatStack < ' _ , ' tcx > ,
1343- witness : WitnessPreference ,
1343+ witness_preference : WitnessPreference ,
13441344 hir_id : HirId ,
13451345) -> Usefulness < ' tcx > {
13461346 let & Matrix ( ref rows) = matrix;
@@ -1353,7 +1353,7 @@ pub fn is_useful<'p, 'a, 'tcx>(
13531353 // the type of the tuple we're checking is inhabited or not.
13541354 if v. is_empty ( ) {
13551355 return if rows. is_empty ( ) {
1356- match witness {
1356+ match witness_preference {
13571357 ConstructWitness => UsefulWithWitness ( vec ! [ Witness ( vec![ ] ) ] ) ,
13581358 LeaveOutWitness => Useful ,
13591359 }
@@ -1408,7 +1408,7 @@ pub fn is_useful<'p, 'a, 'tcx>(
14081408 Some ( hir_id) ,
14091409 )
14101410 . into_iter ( )
1411- . map ( |c| is_useful_specialized ( cx, matrix, v, c, pcx. ty , witness , hir_id) )
1411+ . map ( |c| is_useful_specialized ( cx, matrix, v, c, pcx. ty , witness_preference , hir_id) )
14121412 . find ( |result| result. is_useful ( ) )
14131413 . unwrap_or ( NotUseful )
14141414 } else {
@@ -1475,14 +1475,14 @@ pub fn is_useful<'p, 'a, 'tcx>(
14751475 None ,
14761476 )
14771477 . into_iter ( )
1478- . map ( |c| is_useful_specialized ( cx, matrix, v, c, pcx. ty , witness , hir_id) )
1478+ . map ( |c| is_useful_specialized ( cx, matrix, v, c, pcx. ty , witness_preference , hir_id) )
14791479 . find ( |result| result. is_useful ( ) )
14801480 . unwrap_or ( NotUseful )
14811481 } else {
14821482 let matrix = matrix. specialize_wildcard ( ) ;
14831483 let v = v. to_tail ( ) ;
1484- match is_useful ( cx, & matrix, & v, witness , hir_id) {
1485- UsefulWithWitness ( pats ) => {
1484+ match is_useful ( cx, & matrix, & v, witness_preference , hir_id) {
1485+ UsefulWithWitness ( witnesses ) => {
14861486 let cx = & * cx;
14871487 // In this case, there's at least one "free"
14881488 // constructor that is only matched against by
@@ -1540,7 +1540,7 @@ pub fn is_useful<'p, 'a, 'tcx>(
15401540 missing_ctors. map ( |ctor| ctor. apply_wildcards ( cx, pcx. ty ) ) . collect ( )
15411541 } ;
15421542 // Add the new patterns to each witness
1543- let new_witnesses = pats
1543+ let new_witnesses = witnesses
15441544 . into_iter ( )
15451545 . flat_map ( |witness| {
15461546 new_patterns. iter ( ) . map ( move |pat| {
@@ -1566,16 +1566,16 @@ fn is_useful_specialized<'p, 'a, 'tcx>(
15661566 v : & PatStack < ' _ , ' tcx > ,
15671567 ctor : Constructor < ' tcx > ,
15681568 lty : Ty < ' tcx > ,
1569- witness : WitnessPreference ,
1569+ witness_preference : WitnessPreference ,
15701570 hir_id : HirId ,
15711571) -> Usefulness < ' tcx > {
15721572 debug ! ( "is_useful_specialized({:#?}, {:#?}, {:?})" , v, ctor, lty) ;
15731573
1574- let wild_patterns_owned : Vec < _ > = ctor. wildcard_subpatterns ( cx, lty) . collect ( ) ;
1575- let wild_patterns : Vec < _ > = wild_patterns_owned . iter ( ) . collect ( ) ;
1576- let matrix = matrix. specialize_constructor ( cx, & ctor, & wild_patterns ) ;
1577- match v. specialize_constructor ( cx, & ctor, & wild_patterns ) {
1578- Some ( v) => match is_useful ( cx, & matrix, & v, witness , hir_id) {
1574+ let ctor_wild_subpatterns_owned : Vec < _ > = ctor. wildcard_subpatterns ( cx, lty) . collect ( ) ;
1575+ let ctor_wild_subpatterns : Vec < _ > = ctor_wild_subpatterns_owned . iter ( ) . collect ( ) ;
1576+ let matrix = matrix. specialize_constructor ( cx, & ctor, & ctor_wild_subpatterns ) ;
1577+ match v. specialize_constructor ( cx, & ctor, & ctor_wild_subpatterns ) {
1578+ Some ( v) => match is_useful ( cx, & matrix, & v, witness_preference , hir_id) {
15791579 UsefulWithWitness ( witnesses) => UsefulWithWitness (
15801580 witnesses
15811581 . into_iter ( )
@@ -2000,18 +2000,21 @@ fn constructor_covered_by_range<'tcx>(
20002000fn patterns_for_variant < ' p , ' a : ' p , ' tcx > (
20012001 cx : & mut MatchCheckCtxt < ' a , ' tcx > ,
20022002 subpatterns : & ' p [ FieldPat < ' tcx > ] ,
2003- wild_patterns : & [ & ' p Pat < ' tcx > ] ,
2003+ ctor_wild_subpatterns : & [ & ' p Pat < ' tcx > ] ,
20042004 is_non_exhaustive : bool ,
20052005) -> PatStack < ' p , ' tcx > {
2006- let mut result = SmallVec :: from_slice ( wild_patterns ) ;
2006+ let mut result = SmallVec :: from_slice ( ctor_wild_subpatterns ) ;
20072007
20082008 for subpat in subpatterns {
20092009 if !is_non_exhaustive || !cx. is_uninhabited ( subpat. pattern . ty ) {
20102010 result[ subpat. field . index ( ) ] = & subpat. pattern ;
20112011 }
20122012 }
20132013
2014- debug ! ( "patterns_for_variant({:#?}, {:#?}) = {:#?}" , subpatterns, wild_patterns, result) ;
2014+ debug ! (
2015+ "patterns_for_variant({:#?}, {:#?}) = {:#?}" ,
2016+ subpatterns, ctor_wild_subpatterns, result
2017+ ) ;
20152018 PatStack :: from_vec ( result)
20162019}
20172020
@@ -2027,27 +2030,31 @@ fn specialize<'p, 'a: 'p, 'q: 'p, 'tcx>(
20272030 cx : & mut MatchCheckCtxt < ' a , ' tcx > ,
20282031 r : & PatStack < ' q , ' tcx > ,
20292032 constructor : & Constructor < ' tcx > ,
2030- wild_patterns : & [ & ' p Pat < ' tcx > ] ,
2033+ ctor_wild_subpatterns : & [ & ' p Pat < ' tcx > ] ,
20312034) -> Option < PatStack < ' p , ' tcx > > {
20322035 let pat = r. head ( ) ;
20332036
20342037 let new_head = match * pat. kind {
20352038 PatKind :: AscribeUserType { ref subpattern, .. } => {
2036- specialize ( cx, & PatStack :: from_pattern ( subpattern) , constructor, wild_patterns )
2039+ specialize ( cx, & PatStack :: from_pattern ( subpattern) , constructor, ctor_wild_subpatterns )
20372040 }
20382041
2039- PatKind :: Binding { .. } | PatKind :: Wild => Some ( PatStack :: from_slice ( wild_patterns) ) ,
2042+ PatKind :: Binding { .. } | PatKind :: Wild => {
2043+ Some ( PatStack :: from_slice ( ctor_wild_subpatterns) )
2044+ }
20402045
20412046 PatKind :: Variant { adt_def, variant_index, ref subpatterns, .. } => {
20422047 let ref variant = adt_def. variants [ variant_index] ;
20432048 let is_non_exhaustive = variant. is_field_list_non_exhaustive ( ) && !cx. is_local ( pat. ty ) ;
20442049 Some ( Variant ( variant. def_id ) )
20452050 . filter ( |variant_constructor| variant_constructor == constructor)
2046- . map ( |_| patterns_for_variant ( cx, subpatterns, wild_patterns, is_non_exhaustive) )
2051+ . map ( |_| {
2052+ patterns_for_variant ( cx, subpatterns, ctor_wild_subpatterns, is_non_exhaustive)
2053+ } )
20472054 }
20482055
20492056 PatKind :: Leaf { ref subpatterns } => {
2050- Some ( patterns_for_variant ( cx, subpatterns, wild_patterns , false ) )
2057+ Some ( patterns_for_variant ( cx, subpatterns, ctor_wild_subpatterns , false ) )
20512058 }
20522059
20532060 PatKind :: Deref { ref subpattern } => Some ( PatStack :: from_pattern ( subpattern) ) ,
@@ -2087,7 +2094,7 @@ fn specialize<'p, 'a: 'p, 'q: 'p, 'tcx>(
20872094 constructor,
20882095 ) ,
20892096 } ;
2090- if wild_patterns . len ( ) as u64 == n {
2097+ if ctor_wild_subpatterns . len ( ) as u64 == n {
20912098 // convert a constant slice/array pattern to a list of patterns.
20922099 let layout = cx. tcx . layout_of ( cx. param_env . and ( ty) ) . ok ( ) ?;
20932100 let ptr = Pointer :: new ( AllocId ( 0 ) , offset) ;
@@ -2141,13 +2148,13 @@ fn specialize<'p, 'a: 'p, 'q: 'p, 'tcx>(
21412148 | PatKind :: Slice { ref prefix, ref slice, ref suffix } => match * constructor {
21422149 Slice ( ..) => {
21432150 let pat_len = prefix. len ( ) + suffix. len ( ) ;
2144- if let Some ( slice_count) = wild_patterns . len ( ) . checked_sub ( pat_len) {
2151+ if let Some ( slice_count) = ctor_wild_subpatterns . len ( ) . checked_sub ( pat_len) {
21452152 if slice_count == 0 || slice. is_some ( ) {
21462153 Some (
21472154 prefix
21482155 . iter ( )
21492156 . chain (
2150- wild_patterns
2157+ ctor_wild_subpatterns
21512158 . iter ( )
21522159 . map ( |p| * p)
21532160 . skip ( prefix. len ( ) )
@@ -2185,7 +2192,7 @@ fn specialize<'p, 'a: 'p, 'q: 'p, 'tcx>(
21852192 bug ! ( "support for or-patterns has not been fully implemented yet." ) ;
21862193 }
21872194 } ;
2188- debug ! ( "specialize({:#?}, {:#?}) = {:#?}" , r. head( ) , wild_patterns , new_head) ;
2195+ debug ! ( "specialize({:#?}, {:#?}) = {:#?}" , r. head( ) , ctor_wild_subpatterns , new_head) ;
21892196
21902197 new_head. map ( |head| {
21912198 let mut head = head. 0 ;
0 commit comments