@@ -1434,6 +1434,17 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
14341434 value. fold_with ( & mut r)
14351435 }
14361436
1437+ pub fn resolve_numeric_literals_with_default < T > ( & self , value : T ) -> T
1438+ where
1439+ T : TypeFoldable < ' tcx > ,
1440+ {
1441+ if !value. needs_infer ( ) {
1442+ return value; // Avoid duplicated subst-folding.
1443+ }
1444+ let mut r = InferenceLiteralEraser { infcx : self } ;
1445+ value. fold_with ( & mut r)
1446+ }
1447+
14371448 /// Returns the first unresolved variable contained in `T`. In the
14381449 /// process of visiting `T`, this will resolve (where possible)
14391450 /// type variables in `T`, but it never constructs the final,
@@ -1785,6 +1796,26 @@ impl<'tcx> TyOrConstInferVar<'tcx> {
17851796 }
17861797}
17871798
1799+ /// Replace `{integer}` with `i32` and `{float}` with `f64`.
1800+ /// Used only for diagnostics.
1801+ struct InferenceLiteralEraser < ' a , ' tcx > {
1802+ infcx : & ' a InferCtxt < ' a , ' tcx > ,
1803+ }
1804+
1805+ impl < ' a , ' tcx > TypeFolder < ' tcx > for InferenceLiteralEraser < ' a , ' tcx > {
1806+ fn tcx < ' b > ( & ' b self ) -> TyCtxt < ' tcx > {
1807+ self . infcx . tcx
1808+ }
1809+
1810+ fn fold_ty ( & mut self , ty : Ty < ' tcx > ) -> Ty < ' tcx > {
1811+ match ty. kind ( ) {
1812+ ty:: Infer ( ty:: IntVar ( _) | ty:: FreshIntTy ( _) ) => self . tcx ( ) . types . i32 ,
1813+ ty:: Infer ( ty:: FloatVar ( _) | ty:: FreshFloatTy ( _) ) => self . tcx ( ) . types . f64 ,
1814+ _ => ty. super_fold_with ( self ) ,
1815+ }
1816+ }
1817+ }
1818+
17881819struct ShallowResolver < ' a , ' tcx > {
17891820 infcx : & ' a InferCtxt < ' a , ' tcx > ,
17901821}
0 commit comments