@@ -135,10 +135,7 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
135
135
) ;
136
136
137
137
// Select everything, returning errors.
138
- let true_errors = match fulfill_cx. select_where_possible ( self ) {
139
- Ok ( ( ) ) => vec ! [ ] ,
140
- Err ( errors) => errors,
141
- } ;
138
+ let true_errors = fulfill_cx. select_where_possible ( self ) . err ( ) . unwrap_or_else ( Vec :: new) ;
142
139
debug ! ( "true_errors = {:#?}" , true_errors) ;
143
140
144
141
if !true_errors. is_empty ( ) {
@@ -148,10 +145,7 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
148
145
}
149
146
150
147
// Anything left unselected *now* must be an ambiguity.
151
- let ambig_errors = match fulfill_cx. select_all_or_error ( self ) {
152
- Ok ( ( ) ) => vec ! [ ] ,
153
- Err ( errors) => errors,
154
- } ;
148
+ let ambig_errors = fulfill_cx. select_all_or_error ( self ) . err ( ) . unwrap_or_else ( Vec :: new) ;
155
149
debug ! ( "ambig_errors = {:#?}" , ambig_errors) ;
156
150
157
151
let region_obligations = self . take_registered_region_obligations ( ) ;
@@ -316,16 +310,18 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
316
310
}
317
311
318
312
// ...also include the other query region constraints from the query.
319
- output_query_region_constraints. reserve ( query_result. value . region_constraints . len ( ) ) ;
320
- for r_c in query_result. value . region_constraints . iter ( ) {
321
- let & ty:: OutlivesPredicate ( k1, r2) = r_c. skip_binder ( ) ; // reconstructed below
322
- let k1 = substitute_value ( self . tcx , & result_subst, & k1) ;
323
- let r2 = substitute_value ( self . tcx , & result_subst, & r2) ;
324
- if k1 != r2. into ( ) {
325
- output_query_region_constraints
326
- . push ( ty:: Binder :: bind ( ty:: OutlivesPredicate ( k1, r2) ) ) ;
327
- }
328
- }
313
+ output_query_region_constraints. extend (
314
+ query_result. value . region_constraints . iter ( ) . filter_map ( |r_c| {
315
+ let & ty:: OutlivesPredicate ( k1, r2) = r_c. skip_binder ( ) ; // reconstructed below
316
+ let k1 = substitute_value ( self . tcx , & result_subst, & k1) ;
317
+ let r2 = substitute_value ( self . tcx , & result_subst, & r2) ;
318
+ if k1 != r2. into ( ) {
319
+ Some ( ty:: Binder :: bind ( ty:: OutlivesPredicate ( k1, r2) ) )
320
+ } else {
321
+ None
322
+ }
323
+ } )
324
+ ) ;
329
325
330
326
let user_result: R =
331
327
query_result. substitute_projected ( self . tcx , & result_subst, |q_r| & q_r. value ) ;
@@ -448,10 +444,9 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
448
444
. variables
449
445
. iter ( )
450
446
. enumerate ( )
451
- . map ( |( index, info) | match opt_values[ CanonicalVar :: new ( index) ] {
452
- Some ( k) => k,
453
- None => self . fresh_inference_var_for_canonical_var ( cause. span , * info) ,
454
- } )
447
+ . map ( |( index, info) | opt_values[ CanonicalVar :: new ( index) ] . unwrap_or_else ( ||
448
+ self . fresh_inference_var_for_canonical_var ( cause. span , * info)
449
+ ) )
455
450
. collect ( ) ,
456
451
} ;
457
452
@@ -504,24 +499,22 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
504
499
let ty:: OutlivesPredicate ( k1, r2) = constraint. skip_binder ( ) ; // restored below
505
500
let k1 = substitute_value ( self . tcx , result_subst, k1) ;
506
501
let r2 = substitute_value ( self . tcx , result_subst, r2) ;
507
- match k1. unpack ( ) {
508
- UnpackedKind :: Lifetime ( r1) => Obligation :: new (
509
- cause. clone ( ) ,
510
- param_env,
511
- ty:: Predicate :: RegionOutlives ( ty:: Binder :: dummy (
512
- ty:: OutlivesPredicate ( r1, r2) ,
502
+
503
+ Obligation :: new (
504
+ cause. clone ( ) ,
505
+ param_env,
506
+ match k1. unpack ( ) {
507
+ UnpackedKind :: Lifetime ( r1) => ty:: Predicate :: RegionOutlives (
508
+ ty:: Binder :: dummy (
509
+ ty:: OutlivesPredicate ( r1, r2)
513
510
) ) ,
514
- ) ,
515
-
516
- UnpackedKind :: Type ( t1) => Obligation :: new (
517
- cause. clone ( ) ,
518
- param_env,
519
- ty:: Predicate :: TypeOutlives ( ty:: Binder :: dummy ( ty:: OutlivesPredicate (
520
- t1, r2,
521
- ) ) ) ,
522
- ) ,
523
- }
524
- } ) ,
511
+ UnpackedKind :: Type ( t1) => ty:: Predicate :: TypeOutlives (
512
+ ty:: Binder :: dummy ( ty:: OutlivesPredicate (
513
+ t1, r2
514
+ ) ) )
515
+ }
516
+ )
517
+ } )
525
518
) as Box < dyn Iterator < Item = _ > >
526
519
}
527
520
@@ -583,31 +576,30 @@ pub fn make_query_outlives<'tcx>(
583
576
assert ! ( verifys. is_empty( ) ) ;
584
577
assert ! ( givens. is_empty( ) ) ;
585
578
586
- let mut outlives: Vec < _ > = constraints
587
- . into_iter ( )
588
- . map ( |( k, _) | match * k {
589
- // Swap regions because we are going from sub (<=) to outlives
590
- // (>=).
591
- Constraint :: VarSubVar ( v1, v2) => ty:: OutlivesPredicate (
592
- tcx. mk_region ( ty:: ReVar ( v2) ) . into ( ) ,
593
- tcx. mk_region ( ty:: ReVar ( v1) ) ,
594
- ) ,
595
- Constraint :: VarSubReg ( v1, r2) => {
596
- ty:: OutlivesPredicate ( r2. into ( ) , tcx. mk_region ( ty:: ReVar ( v1) ) )
597
- }
598
- Constraint :: RegSubVar ( r1, v2) => {
599
- ty:: OutlivesPredicate ( tcx. mk_region ( ty:: ReVar ( v2) ) . into ( ) , r1)
600
- }
601
- Constraint :: RegSubReg ( r1, r2) => ty:: OutlivesPredicate ( r2. into ( ) , r1) ,
602
- } )
603
- . map ( ty:: Binder :: dummy) // no bound regions in the code above
604
- . collect ( ) ;
605
-
606
- outlives. extend (
607
- outlives_obligations
608
- . map ( |( ty, r) | ty:: OutlivesPredicate ( ty. into ( ) , r) )
609
- . map ( ty:: Binder :: dummy) , // no bound regions in the code above
610
- ) ;
579
+ let outlives: Vec < _ > = constraints
580
+ . into_iter ( )
581
+ . map ( |( k, _) | match * k {
582
+ // Swap regions because we are going from sub (<=) to outlives
583
+ // (>=).
584
+ Constraint :: VarSubVar ( v1, v2) => ty:: OutlivesPredicate (
585
+ tcx. mk_region ( ty:: ReVar ( v2) ) . into ( ) ,
586
+ tcx. mk_region ( ty:: ReVar ( v1) ) ,
587
+ ) ,
588
+ Constraint :: VarSubReg ( v1, r2) => {
589
+ ty:: OutlivesPredicate ( r2. into ( ) , tcx. mk_region ( ty:: ReVar ( v1) ) )
590
+ }
591
+ Constraint :: RegSubVar ( r1, v2) => {
592
+ ty:: OutlivesPredicate ( tcx. mk_region ( ty:: ReVar ( v2) ) . into ( ) , r1)
593
+ }
594
+ Constraint :: RegSubReg ( r1, r2) => ty:: OutlivesPredicate ( r2. into ( ) , r1) ,
595
+ } )
596
+ . map ( ty:: Binder :: dummy) // no bound regions in the code above
597
+ . chain (
598
+ outlives_obligations
599
+ . map ( |( ty, r) | ty:: OutlivesPredicate ( ty. into ( ) , r) )
600
+ . map ( ty:: Binder :: dummy) , // no bound regions in the code above
601
+ )
602
+ . collect ( ) ;
611
603
612
604
outlives
613
605
}
0 commit comments