@@ -1347,8 +1347,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
13471347 where
13481348 T : TypeFoldable < ' tcx > ,
13491349 {
1350- let mut r = ShallowResolver :: new ( self ) ;
1351- value. fold_with ( & mut r)
1350+ value. fold_with ( & mut ShallowResolver { infcx : self } )
13521351 }
13531352
13541353 pub fn root_var ( & self , var : ty:: TyVid ) -> ty:: TyVid {
@@ -1565,22 +1564,12 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
15651564 // variables, thus we don't need to substitute back the original values.
15661565 self . tcx . const_eval_resolve ( param_env, def_id, substs, promoted, span)
15671566 }
1568- }
1569-
1570- pub struct ShallowResolver < ' a , ' tcx > {
1571- infcx : & ' a InferCtxt < ' a , ' tcx > ,
1572- }
1573-
1574- impl < ' a , ' tcx > ShallowResolver < ' a , ' tcx > {
1575- #[ inline( always) ]
1576- pub fn new ( infcx : & ' a InferCtxt < ' a , ' tcx > ) -> Self {
1577- ShallowResolver { infcx }
1578- }
15791567
15801568 /// If `typ` is a type variable of some kind, resolve it one level
15811569 /// (but do not resolve types found in the result). If `typ` is
15821570 /// not a type variable, just return it unmodified.
1583- pub fn shallow_resolve ( & mut self , typ : Ty < ' tcx > ) -> Ty < ' tcx > {
1571+ // FIXME(eddyb) inline into `ShallowResolver::visit_ty`.
1572+ fn shallow_resolve_ty ( & self , typ : Ty < ' tcx > ) -> Ty < ' tcx > {
15841573 match typ. kind {
15851574 ty:: Infer ( ty:: TyVar ( v) ) => {
15861575 // Not entirely obvious: if `typ` is a type variable,
@@ -1594,78 +1583,80 @@ impl<'a, 'tcx> ShallowResolver<'a, 'tcx> {
15941583 // depth.
15951584 //
15961585 // Note: if these two lines are combined into one we get
1597- // dynamic borrow errors on `self.infcx. inner`.
1598- let known = self . infcx . inner . borrow_mut ( ) . type_variables . probe ( v) . known ( ) ;
1599- known. map ( |t| self . fold_ty ( t) ) . unwrap_or ( typ)
1586+ // dynamic borrow errors on `self.inner`.
1587+ let known = self . inner . borrow_mut ( ) . type_variables . probe ( v) . known ( ) ;
1588+ known. map ( |t| self . shallow_resolve_ty ( t) ) . unwrap_or ( typ)
16001589 }
16011590
16021591 ty:: Infer ( ty:: IntVar ( v) ) => self
1603- . infcx
16041592 . inner
16051593 . borrow_mut ( )
16061594 . int_unification_table
16071595 . probe_value ( v)
1608- . map ( |v| v. to_type ( self . infcx . tcx ) )
1596+ . map ( |v| v. to_type ( self . tcx ) )
16091597 . unwrap_or ( typ) ,
16101598
16111599 ty:: Infer ( ty:: FloatVar ( v) ) => self
1612- . infcx
16131600 . inner
16141601 . borrow_mut ( )
16151602 . float_unification_table
16161603 . probe_value ( v)
1617- . map ( |v| v. to_type ( self . infcx . tcx ) )
1604+ . map ( |v| v. to_type ( self . tcx ) )
16181605 . unwrap_or ( typ) ,
16191606
16201607 _ => typ,
16211608 }
16221609 }
16231610
1624- // `resolver.shallow_resolve_changed(ty )` is equivalent to
1625- // `resolver.shallow_resolve(ty) ! = ty` , but more efficient. It's always
1626- // inlined, despite being large, because it has only two call sites that
1627- // are extremely hot.
1611+ /// `infer_ty_changed(infer_ty )` is equivalent to `shallow_resolve(ty) != ty`
1612+ /// (where `ty.kind = ty::Infer(infer_ty)`) , but more efficient. It's always
1613+ /// inlined, despite being large, because it has only two call sites that
1614+ /// are extremely hot.
16281615 #[ inline( always) ]
1629- pub fn shallow_resolve_changed ( & self , infer : ty:: InferTy ) -> bool {
1630- match infer {
1616+ pub fn infer_ty_changed ( & self , infer_ty : ty:: InferTy ) -> bool {
1617+ match infer_ty {
16311618 ty:: TyVar ( v) => {
16321619 use self :: type_variable:: TypeVariableValue ;
16331620
1634- // If `inlined_probe` returns a `Known` value its `kind` never
1635- // matches `infer `.
1636- match self . infcx . inner . borrow_mut ( ) . type_variables . inlined_probe ( v) {
1621+ // If `inlined_probe` returns a `Known` value, it never equals
1622+ // `ty::Infer(ty::TyVar(v)) `.
1623+ match self . inner . borrow_mut ( ) . type_variables . inlined_probe ( v) {
16371624 TypeVariableValue :: Unknown { .. } => false ,
16381625 TypeVariableValue :: Known { .. } => true ,
16391626 }
16401627 }
16411628
16421629 ty:: IntVar ( v) => {
1643- // If inlined_probe_value returns a value it's always a
1630+ // If ` inlined_probe_value` returns a value it's always a
16441631 // `ty::Int(_)` or `ty::UInt(_)`, which never matches a
16451632 // `ty::Infer(_)`.
1646- self . infcx . inner . borrow_mut ( ) . int_unification_table . inlined_probe_value ( v) . is_some ( )
1633+ self . inner . borrow_mut ( ) . int_unification_table . inlined_probe_value ( v) . is_some ( )
16471634 }
16481635
16491636 ty:: FloatVar ( v) => {
1650- // If inlined_probe_value returns a value it's always a
1637+ // If ` inlined_probe_value` returns a value it's always a
16511638 // `ty::Float(_)`, which never matches a `ty::Infer(_)`.
16521639 //
16531640 // Not `inlined_probe_value(v)` because this call site is colder.
1654- self . infcx . inner . borrow_mut ( ) . float_unification_table . probe_value ( v) . is_some ( )
1641+ self . inner . borrow_mut ( ) . float_unification_table . probe_value ( v) . is_some ( )
16551642 }
16561643
16571644 _ => unreachable ! ( ) ,
16581645 }
16591646 }
16601647}
16611648
1649+ struct ShallowResolver < ' a , ' tcx > {
1650+ infcx : & ' a InferCtxt < ' a , ' tcx > ,
1651+ }
1652+
16621653impl < ' a , ' tcx > TypeFolder < ' tcx > for ShallowResolver < ' a , ' tcx > {
16631654 fn tcx < ' b > ( & ' b self ) -> TyCtxt < ' tcx > {
16641655 self . infcx . tcx
16651656 }
16661657
16671658 fn fold_ty ( & mut self , ty : Ty < ' tcx > ) -> Ty < ' tcx > {
1668- self . shallow_resolve ( ty)
1659+ self . infcx . shallow_resolve_ty ( ty)
16691660 }
16701661
16711662 fn fold_const ( & mut self , ct : & ' tcx ty:: Const < ' tcx > ) -> & ' tcx ty:: Const < ' tcx > {
0 commit comments