@@ -391,13 +391,13 @@ impl<'p, 'tcx> PatStack<'p, 'tcx> {
391
391
& self ,
392
392
cx : & mut MatchCheckCtxt < ' a , ' tcx > ,
393
393
constructor : & Constructor < ' tcx > ,
394
- wild_patterns : & [ & ' q Pat < ' tcx > ] ,
394
+ ctor_wild_subpatterns : & [ & ' q Pat < ' tcx > ] ,
395
395
) -> Option < PatStack < ' q , ' tcx > >
396
396
where
397
397
' a : ' q ,
398
398
' p : ' q ,
399
399
{
400
- specialize ( cx, self , constructor, wild_patterns )
400
+ specialize ( cx, self , constructor, ctor_wild_subpatterns )
401
401
}
402
402
}
403
403
@@ -443,7 +443,7 @@ impl<'p, 'tcx> Matrix<'p, 'tcx> {
443
443
& self ,
444
444
cx : & mut MatchCheckCtxt < ' a , ' tcx > ,
445
445
constructor : & Constructor < ' tcx > ,
446
- wild_patterns : & [ & ' q Pat < ' tcx > ] ,
446
+ ctor_wild_subpatterns : & [ & ' q Pat < ' tcx > ] ,
447
447
) -> Matrix < ' q , ' tcx >
448
448
where
449
449
' a : ' q ,
@@ -452,7 +452,7 @@ impl<'p, 'tcx> Matrix<'p, 'tcx> {
452
452
Matrix (
453
453
self . 0
454
454
. iter ( )
455
- . filter_map ( |r| r. specialize_constructor ( cx, constructor, wild_patterns ) )
455
+ . filter_map ( |r| r. specialize_constructor ( cx, constructor, ctor_wild_subpatterns ) )
456
456
. collect ( ) ,
457
457
)
458
458
}
@@ -1340,7 +1340,7 @@ pub fn is_useful<'p, 'a, 'tcx>(
1340
1340
cx : & mut MatchCheckCtxt < ' a , ' tcx > ,
1341
1341
matrix : & Matrix < ' p , ' tcx > ,
1342
1342
v : & PatStack < ' _ , ' tcx > ,
1343
- witness : WitnessPreference ,
1343
+ witness_preference : WitnessPreference ,
1344
1344
hir_id : HirId ,
1345
1345
) -> Usefulness < ' tcx > {
1346
1346
let & Matrix ( ref rows) = matrix;
@@ -1353,7 +1353,7 @@ pub fn is_useful<'p, 'a, 'tcx>(
1353
1353
// the type of the tuple we're checking is inhabited or not.
1354
1354
if v. is_empty ( ) {
1355
1355
return if rows. is_empty ( ) {
1356
- match witness {
1356
+ match witness_preference {
1357
1357
ConstructWitness => UsefulWithWitness ( vec ! [ Witness ( vec![ ] ) ] ) ,
1358
1358
LeaveOutWitness => Useful ,
1359
1359
}
@@ -1408,7 +1408,7 @@ pub fn is_useful<'p, 'a, 'tcx>(
1408
1408
Some ( hir_id) ,
1409
1409
)
1410
1410
. 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) )
1412
1412
. find ( |result| result. is_useful ( ) )
1413
1413
. unwrap_or ( NotUseful )
1414
1414
} else {
@@ -1475,14 +1475,14 @@ pub fn is_useful<'p, 'a, 'tcx>(
1475
1475
None ,
1476
1476
)
1477
1477
. 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) )
1479
1479
. find ( |result| result. is_useful ( ) )
1480
1480
. unwrap_or ( NotUseful )
1481
1481
} else {
1482
1482
let matrix = matrix. specialize_wildcard ( ) ;
1483
1483
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 ) => {
1486
1486
let cx = & * cx;
1487
1487
// In this case, there's at least one "free"
1488
1488
// constructor that is only matched against by
@@ -1540,7 +1540,7 @@ pub fn is_useful<'p, 'a, 'tcx>(
1540
1540
missing_ctors. map ( |ctor| ctor. apply_wildcards ( cx, pcx. ty ) ) . collect ( )
1541
1541
} ;
1542
1542
// Add the new patterns to each witness
1543
- let new_witnesses = pats
1543
+ let new_witnesses = witnesses
1544
1544
. into_iter ( )
1545
1545
. flat_map ( |witness| {
1546
1546
new_patterns. iter ( ) . map ( move |pat| {
@@ -1566,16 +1566,16 @@ fn is_useful_specialized<'p, 'a, 'tcx>(
1566
1566
v : & PatStack < ' _ , ' tcx > ,
1567
1567
ctor : Constructor < ' tcx > ,
1568
1568
lty : Ty < ' tcx > ,
1569
- witness : WitnessPreference ,
1569
+ witness_preference : WitnessPreference ,
1570
1570
hir_id : HirId ,
1571
1571
) -> Usefulness < ' tcx > {
1572
1572
debug ! ( "is_useful_specialized({:#?}, {:#?}, {:?})" , v, ctor, lty) ;
1573
1573
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) {
1579
1579
UsefulWithWitness ( witnesses) => UsefulWithWitness (
1580
1580
witnesses
1581
1581
. into_iter ( )
@@ -2000,18 +2000,21 @@ fn constructor_covered_by_range<'tcx>(
2000
2000
fn patterns_for_variant < ' p , ' a : ' p , ' tcx > (
2001
2001
cx : & mut MatchCheckCtxt < ' a , ' tcx > ,
2002
2002
subpatterns : & ' p [ FieldPat < ' tcx > ] ,
2003
- wild_patterns : & [ & ' p Pat < ' tcx > ] ,
2003
+ ctor_wild_subpatterns : & [ & ' p Pat < ' tcx > ] ,
2004
2004
is_non_exhaustive : bool ,
2005
2005
) -> PatStack < ' p , ' tcx > {
2006
- let mut result = SmallVec :: from_slice ( wild_patterns ) ;
2006
+ let mut result = SmallVec :: from_slice ( ctor_wild_subpatterns ) ;
2007
2007
2008
2008
for subpat in subpatterns {
2009
2009
if !is_non_exhaustive || !cx. is_uninhabited ( subpat. pattern . ty ) {
2010
2010
result[ subpat. field . index ( ) ] = & subpat. pattern ;
2011
2011
}
2012
2012
}
2013
2013
2014
- debug ! ( "patterns_for_variant({:#?}, {:#?}) = {:#?}" , subpatterns, wild_patterns, result) ;
2014
+ debug ! (
2015
+ "patterns_for_variant({:#?}, {:#?}) = {:#?}" ,
2016
+ subpatterns, ctor_wild_subpatterns, result
2017
+ ) ;
2015
2018
PatStack :: from_vec ( result)
2016
2019
}
2017
2020
@@ -2027,27 +2030,31 @@ fn specialize<'p, 'a: 'p, 'q: 'p, 'tcx>(
2027
2030
cx : & mut MatchCheckCtxt < ' a , ' tcx > ,
2028
2031
r : & PatStack < ' q , ' tcx > ,
2029
2032
constructor : & Constructor < ' tcx > ,
2030
- wild_patterns : & [ & ' p Pat < ' tcx > ] ,
2033
+ ctor_wild_subpatterns : & [ & ' p Pat < ' tcx > ] ,
2031
2034
) -> Option < PatStack < ' p , ' tcx > > {
2032
2035
let pat = r. head ( ) ;
2033
2036
2034
2037
let new_head = match * pat. kind {
2035
2038
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 )
2037
2040
}
2038
2041
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
+ }
2040
2045
2041
2046
PatKind :: Variant { adt_def, variant_index, ref subpatterns, .. } => {
2042
2047
let ref variant = adt_def. variants [ variant_index] ;
2043
2048
let is_non_exhaustive = variant. is_field_list_non_exhaustive ( ) && !cx. is_local ( pat. ty ) ;
2044
2049
Some ( Variant ( variant. def_id ) )
2045
2050
. 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
+ } )
2047
2054
}
2048
2055
2049
2056
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 ) )
2051
2058
}
2052
2059
2053
2060
PatKind :: Deref { ref subpattern } => Some ( PatStack :: from_pattern ( subpattern) ) ,
@@ -2087,7 +2094,7 @@ fn specialize<'p, 'a: 'p, 'q: 'p, 'tcx>(
2087
2094
constructor,
2088
2095
) ,
2089
2096
} ;
2090
- if wild_patterns . len ( ) as u64 == n {
2097
+ if ctor_wild_subpatterns . len ( ) as u64 == n {
2091
2098
// convert a constant slice/array pattern to a list of patterns.
2092
2099
let layout = cx. tcx . layout_of ( cx. param_env . and ( ty) ) . ok ( ) ?;
2093
2100
let ptr = Pointer :: new ( AllocId ( 0 ) , offset) ;
@@ -2141,13 +2148,13 @@ fn specialize<'p, 'a: 'p, 'q: 'p, 'tcx>(
2141
2148
| PatKind :: Slice { ref prefix, ref slice, ref suffix } => match * constructor {
2142
2149
Slice ( ..) => {
2143
2150
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) {
2145
2152
if slice_count == 0 || slice. is_some ( ) {
2146
2153
Some (
2147
2154
prefix
2148
2155
. iter ( )
2149
2156
. chain (
2150
- wild_patterns
2157
+ ctor_wild_subpatterns
2151
2158
. iter ( )
2152
2159
. map ( |p| * p)
2153
2160
. skip ( prefix. len ( ) )
@@ -2185,7 +2192,7 @@ fn specialize<'p, 'a: 'p, 'q: 'p, 'tcx>(
2185
2192
bug ! ( "support for or-patterns has not been fully implemented yet." ) ;
2186
2193
}
2187
2194
} ;
2188
- debug ! ( "specialize({:#?}, {:#?}) = {:#?}" , r. head( ) , wild_patterns , new_head) ;
2195
+ debug ! ( "specialize({:#?}, {:#?}) = {:#?}" , r. head( ) , ctor_wild_subpatterns , new_head) ;
2189
2196
2190
2197
new_head. map ( |head| {
2191
2198
let mut head = head. 0 ;
0 commit comments