@@ -425,16 +425,12 @@ impl<'p, 'tcx> PatStack<'p, 'tcx> {
425
425
}
426
426
427
427
/// This computes `S(constructor, self)`. See top of the file for explanations.
428
- fn specialize_constructor < ' a , ' q > (
428
+ fn specialize_constructor (
429
429
& self ,
430
- cx : & mut MatchCheckCtxt < ' a , ' tcx > ,
430
+ cx : & mut MatchCheckCtxt < ' p , ' tcx > ,
431
431
constructor : & Constructor < ' tcx > ,
432
- ctor_wild_subpatterns : & [ & ' q Pat < ' tcx > ] ,
433
- ) -> Option < PatStack < ' q , ' tcx > >
434
- where
435
- ' a : ' q ,
436
- ' p : ' q ,
437
- {
432
+ ctor_wild_subpatterns : & ' p [ Pat < ' tcx > ] ,
433
+ ) -> Option < PatStack < ' p , ' tcx > > {
438
434
let new_heads = specialize_one_pattern ( cx, self . head ( ) , constructor, ctor_wild_subpatterns) ;
439
435
new_heads. map ( |mut new_head| {
440
436
new_head. 0 . extend_from_slice ( & self . 0 [ 1 ..] ) ;
@@ -486,16 +482,12 @@ impl<'p, 'tcx> Matrix<'p, 'tcx> {
486
482
}
487
483
488
484
/// This computes `S(constructor, self)`. See top of the file for explanations.
489
- fn specialize_constructor < ' a , ' q > (
485
+ fn specialize_constructor (
490
486
& self ,
491
- cx : & mut MatchCheckCtxt < ' a , ' tcx > ,
487
+ cx : & mut MatchCheckCtxt < ' p , ' tcx > ,
492
488
constructor : & Constructor < ' tcx > ,
493
- ctor_wild_subpatterns : & [ & ' q Pat < ' tcx > ] ,
494
- ) -> Matrix < ' q , ' tcx >
495
- where
496
- ' a : ' q ,
497
- ' p : ' q ,
498
- {
489
+ ctor_wild_subpatterns : & ' p [ Pat < ' tcx > ] ,
490
+ ) -> Matrix < ' p , ' tcx > {
499
491
self . 0
500
492
. iter ( )
501
493
. filter_map ( |r| r. specialize_constructor ( cx, constructor, ctor_wild_subpatterns) )
@@ -1604,10 +1596,10 @@ impl<'tcx> fmt::Debug for MissingConstructors<'tcx> {
1604
1596
/// relation to preceding patterns, it is not reachable) and exhaustiveness
1605
1597
/// checking (if a wildcard pattern is useful in relation to a matrix, the
1606
1598
/// matrix isn't exhaustive).
1607
- pub fn is_useful < ' p , ' a , ' tcx > (
1608
- cx : & mut MatchCheckCtxt < ' a , ' tcx > ,
1599
+ pub fn is_useful < ' p , ' tcx > (
1600
+ cx : & mut MatchCheckCtxt < ' p , ' tcx > ,
1609
1601
matrix : & Matrix < ' p , ' tcx > ,
1610
- v : & PatStack < ' _ , ' tcx > ,
1602
+ v : & PatStack < ' p , ' tcx > ,
1611
1603
witness_preference : WitnessPreference ,
1612
1604
hir_id : HirId ,
1613
1605
) -> Usefulness < ' tcx > {
@@ -1768,21 +1760,21 @@ pub fn is_useful<'p, 'a, 'tcx>(
1768
1760
1769
1761
/// A shorthand for the `U(S(c, P), S(c, q))` operation from the paper. I.e., `is_useful` applied
1770
1762
/// to the specialised version of both the pattern matrix `P` and the new pattern `q`.
1771
- fn is_useful_specialized < ' p , ' a , ' tcx > (
1772
- cx : & mut MatchCheckCtxt < ' a , ' tcx > ,
1763
+ fn is_useful_specialized < ' p , ' tcx > (
1764
+ cx : & mut MatchCheckCtxt < ' p , ' tcx > ,
1773
1765
matrix : & Matrix < ' p , ' tcx > ,
1774
- v : & PatStack < ' _ , ' tcx > ,
1766
+ v : & PatStack < ' p , ' tcx > ,
1775
1767
ctor : Constructor < ' tcx > ,
1776
1768
lty : Ty < ' tcx > ,
1777
1769
witness_preference : WitnessPreference ,
1778
1770
hir_id : HirId ,
1779
1771
) -> Usefulness < ' tcx > {
1780
1772
debug ! ( "is_useful_specialized({:#?}, {:#?}, {:?})" , v, ctor, lty) ;
1781
1773
1782
- let ctor_wild_subpatterns_owned : Vec < _ > = ctor . wildcard_subpatterns ( cx , lty ) ;
1783
- let ctor_wild_subpatterns : Vec < _ > = ctor_wild_subpatterns_owned . iter ( ) . collect ( ) ;
1784
- let matrix = matrix. specialize_constructor ( cx, & ctor, & ctor_wild_subpatterns) ;
1785
- v. specialize_constructor ( cx, & ctor, & ctor_wild_subpatterns)
1774
+ let ctor_wild_subpatterns =
1775
+ cx . pattern_arena . alloc_from_iter ( ctor . wildcard_subpatterns ( cx , lty ) ) ;
1776
+ let matrix = matrix. specialize_constructor ( cx, & ctor, ctor_wild_subpatterns) ;
1777
+ v. specialize_constructor ( cx, & ctor, ctor_wild_subpatterns)
1786
1778
. map ( |v| is_useful ( cx, & matrix, & v, witness_preference, hir_id) )
1787
1779
. map ( |u| u. apply_constructor ( cx, & ctor, lty) )
1788
1780
. unwrap_or ( NotUseful )
@@ -2250,13 +2242,13 @@ fn constructor_covered_by_range<'tcx>(
2250
2242
if intersects { Some ( ( ) ) } else { None }
2251
2243
}
2252
2244
2253
- fn patterns_for_variant < ' p , ' a : ' p , ' tcx > (
2254
- cx : & mut MatchCheckCtxt < ' a , ' tcx > ,
2245
+ fn patterns_for_variant < ' p , ' tcx > (
2246
+ cx : & mut MatchCheckCtxt < ' p , ' tcx > ,
2255
2247
subpatterns : & ' p [ FieldPat < ' tcx > ] ,
2256
- ctor_wild_subpatterns : & [ & ' p Pat < ' tcx > ] ,
2248
+ ctor_wild_subpatterns : & ' p [ Pat < ' tcx > ] ,
2257
2249
is_non_exhaustive : bool ,
2258
2250
) -> PatStack < ' p , ' tcx > {
2259
- let mut result = SmallVec :: from_slice ( ctor_wild_subpatterns) ;
2251
+ let mut result: SmallVec < _ > = ctor_wild_subpatterns. iter ( ) . collect ( ) ;
2260
2252
2261
2253
for subpat in subpatterns {
2262
2254
if !is_non_exhaustive || !cx. is_uninhabited ( subpat. pattern . ty ) {
@@ -2280,11 +2272,11 @@ fn patterns_for_variant<'p, 'a: 'p, 'tcx>(
2280
2272
/// different patterns.
2281
2273
/// Structure patterns with a partial wild pattern (Foo { a: 42, .. }) have their missing
2282
2274
/// fields filled with wild patterns.
2283
- fn specialize_one_pattern < ' p , ' a : ' p , ' q : ' p , ' tcx > (
2284
- cx : & mut MatchCheckCtxt < ' a , ' tcx > ,
2285
- pat : & ' q Pat < ' tcx > ,
2275
+ fn specialize_one_pattern < ' p , ' tcx > (
2276
+ cx : & mut MatchCheckCtxt < ' p , ' tcx > ,
2277
+ pat : & ' p Pat < ' tcx > ,
2286
2278
constructor : & Constructor < ' tcx > ,
2287
- ctor_wild_subpatterns : & [ & ' p Pat < ' tcx > ] ,
2279
+ ctor_wild_subpatterns : & ' p [ Pat < ' tcx > ] ,
2288
2280
) -> Option < PatStack < ' p , ' tcx > > {
2289
2281
if let NonExhaustive = constructor {
2290
2282
// Only a wildcard pattern can match the special extra constructor
@@ -2294,9 +2286,7 @@ fn specialize_one_pattern<'p, 'a: 'p, 'q: 'p, 'tcx>(
2294
2286
let result = match * pat. kind {
2295
2287
PatKind :: AscribeUserType { .. } => bug ! ( ) , // Handled by `expand_pattern`
2296
2288
2297
- PatKind :: Binding { .. } | PatKind :: Wild => {
2298
- Some ( PatStack :: from_slice ( ctor_wild_subpatterns) )
2299
- }
2289
+ PatKind :: Binding { .. } | PatKind :: Wild => Some ( ctor_wild_subpatterns. iter ( ) . collect ( ) ) ,
2300
2290
2301
2291
PatKind :: Variant { adt_def, variant_index, ref subpatterns, .. } => {
2302
2292
let ref variant = adt_def. variants [ variant_index] ;
@@ -2406,7 +2396,6 @@ fn specialize_one_pattern<'p, 'a: 'p, 'q: 'p, 'tcx>(
2406
2396
. chain (
2407
2397
ctor_wild_subpatterns
2408
2398
. iter ( )
2409
- . map ( |p| * p)
2410
2399
. skip ( prefix. len ( ) )
2411
2400
. take ( slice_count)
2412
2401
. chain ( suffix. iter ( ) ) ,
0 commit comments