@@ -86,8 +86,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
86
86
if !matches ! ( a. kind( ) , ty:: Opaque ( ..) ) {
87
87
return None ;
88
88
}
89
- Instantiator { infcx : self , cause : cause. clone ( ) , param_env }
90
- . fold_opaque_ty_new ( a, |_, _| b)
89
+ self . fold_opaque_ty_new ( a, cause. clone ( ) , param_env, |_, _| b)
91
90
} ;
92
91
if let Some ( res) = process ( a, b) {
93
92
res
@@ -480,16 +479,12 @@ impl UseKind {
480
479
}
481
480
}
482
481
483
- struct Instantiator < ' a , ' tcx > {
484
- infcx : & ' a InferCtxt < ' a , ' tcx > ,
485
- cause : ObligationCause < ' tcx > ,
486
- param_env : ty:: ParamEnv < ' tcx > ,
487
- }
488
-
489
- impl < ' a , ' tcx > Instantiator < ' a , ' tcx > {
482
+ impl < ' a , ' tcx > InferCtxt < ' a , ' tcx > {
490
483
fn fold_opaque_ty_new (
491
- & mut self ,
484
+ & self ,
492
485
ty : Ty < ' tcx > ,
486
+ cause : ObligationCause < ' tcx > ,
487
+ param_env : ty:: ParamEnv < ' tcx > ,
493
488
mk_ty : impl FnOnce ( & InferCtxt < ' _ , ' tcx > , Span ) -> Ty < ' tcx > ,
494
489
) -> Option < InferResult < ' tcx , ( ) > > {
495
490
// Check that this is `impl Trait` type is
@@ -527,9 +522,8 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
527
522
// }
528
523
// ```
529
524
let opaque_type_key = ty. expect_opaque_type ( ) ;
530
- if let Some ( origin) = self . infcx . opaque_type_origin ( opaque_type_key. def_id , self . cause . span )
531
- {
532
- return Some ( self . fold_opaque_ty ( ty, opaque_type_key, origin, mk_ty) ) ;
525
+ if let Some ( origin) = self . opaque_type_origin ( opaque_type_key. def_id , cause. span ) {
526
+ return Some ( self . fold_opaque_ty ( ty, cause, param_env, opaque_type_key, origin, mk_ty) ) ;
533
527
}
534
528
535
529
debug ! ( ?ty, "encountered opaque outside its definition scope" , ) ;
@@ -538,34 +532,35 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
538
532
539
533
#[ instrument( skip( self , mk_ty) , level = "debug" ) ]
540
534
fn fold_opaque_ty (
541
- & mut self ,
535
+ & self ,
542
536
ty : Ty < ' tcx > ,
537
+ cause : ObligationCause < ' tcx > ,
538
+ param_env : ty:: ParamEnv < ' tcx > ,
543
539
opaque_type_key : OpaqueTypeKey < ' tcx > ,
544
540
origin : hir:: OpaqueTyOrigin ,
545
541
mk_ty : impl FnOnce ( & InferCtxt < ' _ , ' tcx > , Span ) -> Ty < ' tcx > ,
546
542
) -> InferResult < ' tcx , ( ) > {
547
- let infcx = self . infcx ;
548
- let tcx = infcx. tcx ;
543
+ let tcx = self . tcx ;
549
544
let OpaqueTypeKey { def_id, substs } = opaque_type_key;
550
545
551
- let ty_var = mk_ty ( infcx , self . cause . span ) ;
546
+ let ty_var = mk_ty ( self , cause. span ) ;
552
547
553
548
// Ideally, we'd get the span where *this specific `ty` came
554
549
// from*, but right now we just use the span from the overall
555
550
// value being folded. In simple cases like `-> impl Foo`,
556
551
// these are the same span, but not in cases like `-> (impl
557
552
// Foo, impl Bar)`.
558
- let span = self . cause . span ;
553
+ let span = cause. span ;
559
554
560
555
let mut obligations = vec ! [ ] ;
561
- let prev = self . infcx . inner . borrow_mut ( ) . opaque_types ( ) . register (
556
+ let prev = self . inner . borrow_mut ( ) . opaque_types ( ) . register (
562
557
OpaqueTypeKey { def_id, substs } ,
563
558
ty,
564
559
OpaqueHiddenType { ty : ty_var, span } ,
565
560
origin,
566
561
) ;
567
562
if let Some ( prev) = prev {
568
- obligations = self . infcx . at ( & self . cause , self . param_env ) . eq ( prev, ty_var) ?. obligations ;
563
+ obligations = self . at ( & cause, param_env) . eq ( prev, ty_var) ?. obligations ;
569
564
}
570
565
571
566
debug ! ( "generated new type inference var {:?}" , ty_var. kind( ) ) ;
@@ -581,10 +576,10 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
581
576
ty_op : |ty| match * ty. kind ( ) {
582
577
// We can't normalize associated types from `rustc_infer`,
583
578
// but we can eagerly register inference variables for them.
584
- ty:: Projection ( projection_ty) if !projection_ty. has_escaping_bound_vars ( ) => infcx . infer_projection (
585
- self . param_env ,
579
+ ty:: Projection ( projection_ty) if !projection_ty. has_escaping_bound_vars ( ) => self . infer_projection (
580
+ param_env,
586
581
projection_ty,
587
- self . cause . clone ( ) ,
582
+ cause. clone ( ) ,
588
583
0 ,
589
584
& mut obligations,
590
585
) ,
@@ -608,11 +603,7 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
608
603
}
609
604
// Require that the predicate holds for the concrete type.
610
605
debug ! ( ?predicate) ;
611
- obligations. push ( traits:: Obligation :: new (
612
- self . cause . clone ( ) ,
613
- self . param_env ,
614
- predicate,
615
- ) ) ;
606
+ obligations. push ( traits:: Obligation :: new ( cause. clone ( ) , param_env, predicate) ) ;
616
607
}
617
608
Ok ( InferOk { value : ( ) , obligations } )
618
609
}
0 commit comments