@@ -30,7 +30,7 @@ use rustc_middle::ty::relate::RelateResult;
30
30
use rustc_middle:: ty:: subst:: { GenericArg , GenericArgKind , InternalSubsts , SubstsRef } ;
31
31
use rustc_middle:: ty:: visit:: TypeVisitable ;
32
32
pub 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 } ;
34
34
use rustc_middle:: ty:: { ConstVid , FloatVid , IntVid , TyVid } ;
35
35
use rustc_span:: symbol:: Symbol ;
36
36
use rustc_span:: Span ;
@@ -1870,9 +1870,33 @@ impl<'a, 'tcx> TypeFolder<'tcx> for ShallowResolver<'a, 'tcx> {
1870
1870
/// If `ty` is a type variable of some kind, resolve it one level
1871
1871
/// (but do not resolve types found in the result). If `typ` is
1872
1872
/// not a type variable, just return it unmodified.
1873
+ #[ inline]
1873
1874
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) => {
1876
1900
// Not entirely obvious: if `typ` is a type variable,
1877
1901
// it can be resolved to an int/float variable, which
1878
1902
// can then be recursively resolved, hence the
@@ -1886,41 +1910,26 @@ impl<'a, 'tcx> TypeFolder<'tcx> for ShallowResolver<'a, 'tcx> {
1886
1910
// Note: if these two lines are combined into one we get
1887
1911
// dynamic borrow errors on `self.inner`.
1888
1912
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) )
1890
1914
}
1891
1915
1892
- ty:: Infer ( ty :: IntVar ( v) ) => self
1916
+ ty:: IntVar ( v) => self
1893
1917
. infcx
1894
1918
. inner
1895
1919
. borrow_mut ( )
1896
1920
. int_unification_table ( )
1897
1921
. probe_value ( v)
1898
- . map_or ( ty , |v| v. to_type ( self . infcx . tcx ) ) ,
1922
+ . map ( |v| v. to_type ( self . infcx . tcx ) ) ,
1899
1923
1900
- ty:: Infer ( ty :: FloatVar ( v) ) => self
1924
+ ty:: FloatVar ( v) => self
1901
1925
. infcx
1902
1926
. inner
1903
1927
. borrow_mut ( )
1904
1928
. float_unification_table ( )
1905
1929
. 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 ) ) ,
1911
1931
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 ,
1924
1933
}
1925
1934
}
1926
1935
}
0 commit comments