@@ -1724,6 +1724,12 @@ enum TupleArgumentsFlag {
17241724 TupleArguments ,
17251725}
17261726
1727+ #[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
1728+ pub enum Fallback {
1729+ Full ,
1730+ Numeric
1731+ }
1732+
17271733impl < ' a , ' gcx , ' tcx > FnCtxt < ' a , ' gcx , ' tcx > {
17281734 pub fn new ( inh : & ' a Inherited < ' a , ' gcx , ' tcx > ,
17291735 param_env : ty:: ParamEnv < ' tcx > ,
@@ -2133,7 +2139,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
21332139 // unconstrained floats with f64.
21342140 // Defaulting inference variables becomes very dubious if we have
21352141 // encountered type-checking errors. In that case, fallback to TyError.
2136- fn apply_fallback_if_possible ( & self , ty : Ty < ' tcx > ) {
2142+ fn apply_fallback_if_possible ( & self , ty : Ty < ' tcx > , fallback : Fallback ) {
21372143 use rustc:: ty:: error:: UnconstrainedNumeric :: Neither ;
21382144 use rustc:: ty:: error:: UnconstrainedNumeric :: { UnconstrainedInt , UnconstrainedFloat } ;
21392145
@@ -2142,7 +2148,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
21422148 _ if self . is_tainted_by_errors ( ) => self . tcx ( ) . types . err ,
21432149 UnconstrainedInt => self . tcx . types . i32 ,
21442150 UnconstrainedFloat => self . tcx . types . f64 ,
2145- Neither if self . type_var_diverges ( ty) => self . tcx . mk_diverging_default ( ) ,
2151+ Neither if self . type_var_diverges ( ty) && fallback == Fallback :: Full
2152+ => self . tcx . mk_diverging_default ( ) ,
21462153 Neither => return
21472154 } ;
21482155 debug ! ( "default_type_parameters: defaulting `{:?}` to `{:?}`" , ty, fallback) ;
@@ -2159,7 +2166,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
21592166 self . select_obligations_where_possible ( ) ;
21602167
21612168 for ty in & self . unsolved_variables ( ) {
2162- self . apply_fallback_if_possible ( ty) ;
2169+ self . apply_fallback_if_possible ( ty, Fallback :: Full ) ;
21632170 }
21642171
21652172 let mut fulfillment_cx = self . fulfillment_cx . borrow_mut ( ) ;
@@ -4937,22 +4944,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
49374944 }
49384945 }
49394946
4940- // Same as `structurally_resolved_type` but also resolves numeric vars, with fallback.
4941- pub fn resolved_type ( & self , sp : Span , ty : Ty < ' tcx > ) -> Ty < ' tcx > {
4942- let mut ty = self . resolve_type_vars_with_obligations ( ty) ;
4943- if !ty. is_ty_infer ( ) {
4944- return ty;
4945- } else {
4946- self . apply_fallback_if_possible ( ty) ;
4947- ty = self . resolve_type_vars_with_obligations ( ty) ;
4948- if !ty. is_ty_infer ( ) {
4949- ty
4950- } else { // Fallback failed, error.
4951- self . must_be_known_in_context ( sp, ty)
4952- }
4953- }
4954- }
4955-
49564947 fn must_be_known_in_context ( & self , sp : Span , ty : Ty < ' tcx > ) -> Ty < ' tcx > {
49574948 if !self . is_tainted_by_errors ( ) {
49584949 type_error_struct ! ( self . tcx. sess, sp, ty, E0619 ,
0 commit comments