@@ -30,11 +30,10 @@ use rustc_middle::traits::ObligationCause;
30
30
use rustc_middle:: ty:: error:: TypeError ;
31
31
use rustc_middle:: ty:: fold:: FnMutDelegate ;
32
32
use rustc_middle:: ty:: relate:: { self , Relate , RelateResult , TypeRelation } ;
33
- use rustc_middle:: ty:: visit:: { TypeSuperVisitable , TypeVisitable , TypeVisitableExt , TypeVisitor } ;
33
+ use rustc_middle:: ty:: visit:: TypeVisitableExt ;
34
34
use rustc_middle:: ty:: { self , InferConst , Ty , TyCtxt } ;
35
35
use rustc_span:: { Span , Symbol } ;
36
36
use std:: fmt:: Debug ;
37
- use std:: ops:: ControlFlow ;
38
37
39
38
use super :: combine:: ObligationEmittingRelation ;
40
39
@@ -115,11 +114,6 @@ pub trait TypeRelatingDelegate<'tcx> {
115
114
fn forbid_inference_vars ( ) -> bool ;
116
115
}
117
116
118
- #[ derive( Clone , Debug , Default ) ]
119
- struct BoundRegionScope < ' tcx > {
120
- map : FxHashMap < ty:: BoundRegion , ty:: Region < ' tcx > > ,
121
- }
122
-
123
117
#[ derive( Copy , Clone ) ]
124
118
struct UniversallyQuantified ( bool ) ;
125
119
@@ -230,10 +224,13 @@ where
230
224
) -> RelateResult < ' tcx , T > {
231
225
let universe = self . infcx . probe_ty_var ( for_vid) . unwrap_err ( ) ;
232
226
227
+ if value. has_escaping_bound_vars ( ) {
228
+ bug ! ( "trying to instantiate {for_vid:?} with escaping bound vars: {value:?}" ) ;
229
+ }
230
+
233
231
let mut generalizer = TypeGeneralizer {
234
232
infcx : self . infcx ,
235
233
delegate : & mut self . delegate ,
236
- first_free_index : ty:: INNERMOST ,
237
234
ambient_variance : self . ambient_variance ,
238
235
for_vid_sub_root : self . infcx . inner . borrow_mut ( ) . type_variables ( ) . sub_root_var ( for_vid) ,
239
236
universe,
@@ -488,13 +485,7 @@ where
488
485
}
489
486
490
487
if a == b {
491
- // Subtle: if a or b has a bound variable that we are lazily
492
- // substituting, then even if a == b, it could be that the values we
493
- // will substitute for those bound variables are *not* the same, and
494
- // hence returning `Ok(a)` is incorrect.
495
- if !a. has_escaping_bound_vars ( ) && !b. has_escaping_bound_vars ( ) {
496
- return Ok ( a) ;
497
- }
488
+ return Ok ( a) ;
498
489
}
499
490
500
491
match ( a. kind ( ) , b. kind ( ) ) {
@@ -726,47 +717,6 @@ where
726
717
}
727
718
}
728
719
729
- /// When we encounter a binder like `for<..> fn(..)`, we actually have
730
- /// to walk the `fn` value to find all the values bound by the `for`
731
- /// (these are not explicitly present in the ty representation right
732
- /// now). This visitor handles that: it descends the type, tracking
733
- /// binder depth, and finds late-bound regions targeting the
734
- /// `for<..`>. For each of those, it creates an entry in
735
- /// `bound_region_scope`.
736
- struct ScopeInstantiator < ' me , ' tcx > {
737
- next_region : & ' me mut dyn FnMut ( ty:: BoundRegion ) -> ty:: Region < ' tcx > ,
738
- // The debruijn index of the scope we are instantiating.
739
- target_index : ty:: DebruijnIndex ,
740
- bound_region_scope : & ' me mut BoundRegionScope < ' tcx > ,
741
- }
742
-
743
- impl < ' me , ' tcx > TypeVisitor < TyCtxt < ' tcx > > for ScopeInstantiator < ' me , ' tcx > {
744
- fn visit_binder < T : TypeVisitable < TyCtxt < ' tcx > > > (
745
- & mut self ,
746
- t : & ty:: Binder < ' tcx , T > ,
747
- ) -> ControlFlow < Self :: BreakTy > {
748
- self . target_index . shift_in ( 1 ) ;
749
- t. super_visit_with ( self ) ;
750
- self . target_index . shift_out ( 1 ) ;
751
-
752
- ControlFlow :: Continue ( ( ) )
753
- }
754
-
755
- fn visit_region ( & mut self , r : ty:: Region < ' tcx > ) -> ControlFlow < Self :: BreakTy > {
756
- let ScopeInstantiator { bound_region_scope, next_region, .. } = self ;
757
-
758
- match * r {
759
- ty:: ReLateBound ( debruijn, br) if debruijn == self . target_index => {
760
- bound_region_scope. map . entry ( br) . or_insert_with ( || next_region ( br) ) ;
761
- }
762
-
763
- _ => { }
764
- }
765
-
766
- ControlFlow :: Continue ( ( ) )
767
- }
768
- }
769
-
770
720
/// The "type generalizer" is used when handling inference variables.
771
721
///
772
722
/// The basic strategy for handling a constraint like `?A <: B` is to
@@ -780,11 +730,6 @@ impl<'me, 'tcx> TypeVisitor<TyCtxt<'tcx>> for ScopeInstantiator<'me, 'tcx> {
780
730
/// value of `A`. Finally, we relate `&'0 u32 <: &'x u32`, which
781
731
/// establishes `'0: 'x` as a constraint.
782
732
///
783
- /// As a side-effect of this generalization procedure, we also replace
784
- /// all the bound regions that we have traversed with concrete values,
785
- /// so that the resulting generalized type is independent from the
786
- /// scopes.
787
- ///
788
733
/// [blog post]: https://is.gd/0hKvIr
789
734
struct TypeGeneralizer < ' me , ' tcx , D >
790
735
where
@@ -798,8 +743,6 @@ where
798
743
/// some other type. What will be the variance at this point?
799
744
ambient_variance : ty:: Variance ,
800
745
801
- first_free_index : ty:: DebruijnIndex ,
802
-
803
746
/// The vid of the type variable that is in the process of being
804
747
/// instantiated. If we find this within the value we are folding,
805
748
/// that means we would have created a cyclic value.
@@ -939,7 +882,7 @@ where
939
882
) -> RelateResult < ' tcx , ty:: Region < ' tcx > > {
940
883
debug ! ( "TypeGeneralizer::regions(a={:?})" , a) ;
941
884
942
- if let ty:: ReLateBound ( debruijn , _ ) = * a && debruijn < self . first_free_index {
885
+ if let ty:: ReLateBound ( .. ) = * a {
943
886
return Ok ( a) ;
944
887
}
945
888
@@ -958,7 +901,6 @@ where
958
901
// FIXME(#54105) -- if the ambient variance is bivariant,
959
902
// though, we may however need to check well-formedness or
960
903
// risk a problem like #41677 again.
961
-
962
904
let replacement_region_vid = self . delegate . generalize_existential ( self . universe ) ;
963
905
964
906
Ok ( replacement_region_vid)
@@ -1002,10 +944,7 @@ where
1002
944
T : Relate < ' tcx > ,
1003
945
{
1004
946
debug ! ( "TypeGeneralizer::binders(a={:?})" , a) ;
1005
-
1006
- self . first_free_index . shift_in ( 1 ) ;
1007
947
let result = self . relate ( a. skip_binder ( ) , a. skip_binder ( ) ) ?;
1008
- self . first_free_index . shift_out ( 1 ) ;
1009
948
Ok ( a. rebind ( result) )
1010
949
}
1011
950
}
0 commit comments