@@ -30,7 +30,7 @@ use rustc_middle::ty::relate::RelateResult;
3030use rustc_middle:: ty:: subst:: { GenericArg , GenericArgKind , InternalSubsts , SubstsRef } ;
3131use rustc_middle:: ty:: visit:: TypeVisitable ;
3232pub use rustc_middle:: ty:: IntVarValue ;
33- use rustc_middle:: ty:: { self , GenericParamDefKind , InferConst , Ty , TyCtxt } ;
33+ use rustc_middle:: ty:: { self , GenericParamDefKind , InferConst , InferTy , Ty , TyCtxt } ;
3434use rustc_middle:: ty:: { ConstVid , FloatVid , IntVid , TyVid } ;
3535use rustc_span:: symbol:: Symbol ;
3636use rustc_span:: Span ;
@@ -1870,9 +1870,33 @@ impl<'a, 'tcx> TypeFolder<'tcx> for ShallowResolver<'a, 'tcx> {
18701870 /// If `ty` is a type variable of some kind, resolve it one level
18711871 /// (but do not resolve types found in the result). If `typ` is
18721872 /// not a type variable, just return it unmodified.
1873+ #[ inline]
18731874 fn fold_ty ( & mut self , ty : Ty < ' tcx > ) -> Ty < ' tcx > {
1874- match * ty. kind ( ) {
1875- ty:: Infer ( ty:: TyVar ( v) ) => {
1875+ if let ty:: Infer ( v) = ty. kind ( ) { self . fold_infer_ty ( * v) . unwrap_or ( ty) } else { ty }
1876+ }
1877+
1878+ fn fold_const ( & mut self , ct : ty:: Const < ' tcx > ) -> ty:: Const < ' tcx > {
1879+ if let ty:: ConstKind :: Infer ( InferConst :: Var ( vid) ) = ct. kind ( ) {
1880+ self . infcx
1881+ . inner
1882+ . borrow_mut ( )
1883+ . const_unification_table ( )
1884+ . probe_value ( vid)
1885+ . val
1886+ . known ( )
1887+ . unwrap_or ( ct)
1888+ } else {
1889+ ct
1890+ }
1891+ }
1892+ }
1893+
1894+ impl < ' a , ' tcx > ShallowResolver < ' a , ' tcx > {
1895+ // This is separate from `fold_ty` to keep that method small and inlinable.
1896+ #[ inline( never) ]
1897+ fn fold_infer_ty ( & mut self , v : InferTy ) -> Option < Ty < ' tcx > > {
1898+ match v {
1899+ ty:: TyVar ( v) => {
18761900 // Not entirely obvious: if `typ` is a type variable,
18771901 // it can be resolved to an int/float variable, which
18781902 // can then be recursively resolved, hence the
@@ -1886,41 +1910,26 @@ impl<'a, 'tcx> TypeFolder<'tcx> for ShallowResolver<'a, 'tcx> {
18861910 // Note: if these two lines are combined into one we get
18871911 // dynamic borrow errors on `self.inner`.
18881912 let known = self . infcx . inner . borrow_mut ( ) . type_variables ( ) . probe ( v) . known ( ) ;
1889- known. map_or ( ty , |t| self . fold_ty ( t) )
1913+ known. map ( |t| self . fold_ty ( t) )
18901914 }
18911915
1892- ty:: Infer ( ty :: IntVar ( v) ) => self
1916+ ty:: IntVar ( v) => self
18931917 . infcx
18941918 . inner
18951919 . borrow_mut ( )
18961920 . int_unification_table ( )
18971921 . probe_value ( v)
1898- . map_or ( ty , |v| v. to_type ( self . infcx . tcx ) ) ,
1922+ . map ( |v| v. to_type ( self . infcx . tcx ) ) ,
18991923
1900- ty:: Infer ( ty :: FloatVar ( v) ) => self
1924+ ty:: FloatVar ( v) => self
19011925 . infcx
19021926 . inner
19031927 . borrow_mut ( )
19041928 . float_unification_table ( )
19051929 . probe_value ( v)
1906- . map_or ( ty, |v| v. to_type ( self . infcx . tcx ) ) ,
1907-
1908- _ => ty,
1909- }
1910- }
1930+ . map ( |v| v. to_type ( self . infcx . tcx ) ) ,
19111931
1912- fn fold_const ( & mut self , ct : ty:: Const < ' tcx > ) -> ty:: Const < ' tcx > {
1913- if let ty:: ConstKind :: Infer ( InferConst :: Var ( vid) ) = ct. kind ( ) {
1914- self . infcx
1915- . inner
1916- . borrow_mut ( )
1917- . const_unification_table ( )
1918- . probe_value ( vid)
1919- . val
1920- . known ( )
1921- . unwrap_or ( ct)
1922- } else {
1923- ct
1932+ ty:: FreshTy ( _) | ty:: FreshIntTy ( _) | ty:: FreshFloatTy ( _) => None ,
19241933 }
19251934 }
19261935}
0 commit comments