@@ -1724,6 +1724,12 @@ enum TupleArgumentsFlag {
1724
1724
TupleArguments ,
1725
1725
}
1726
1726
1727
+ #[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
1728
+ pub enum Fallback {
1729
+ Full ,
1730
+ Numeric
1731
+ }
1732
+
1727
1733
impl < ' a , ' gcx , ' tcx > FnCtxt < ' a , ' gcx , ' tcx > {
1728
1734
pub fn new ( inh : & ' a Inherited < ' a , ' gcx , ' tcx > ,
1729
1735
param_env : ty:: ParamEnv < ' tcx > ,
@@ -2133,7 +2139,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
2133
2139
// unconstrained floats with f64.
2134
2140
// Defaulting inference variables becomes very dubious if we have
2135
2141
// 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 ) {
2137
2143
use rustc:: ty:: error:: UnconstrainedNumeric :: Neither ;
2138
2144
use rustc:: ty:: error:: UnconstrainedNumeric :: { UnconstrainedInt , UnconstrainedFloat } ;
2139
2145
@@ -2142,7 +2148,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
2142
2148
_ if self . is_tainted_by_errors ( ) => self . tcx ( ) . types . err ,
2143
2149
UnconstrainedInt => self . tcx . types . i32 ,
2144
2150
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 ( ) ,
2146
2153
Neither => return
2147
2154
} ;
2148
2155
debug ! ( "default_type_parameters: defaulting `{:?}` to `{:?}`" , ty, fallback) ;
@@ -2159,7 +2166,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
2159
2166
self . select_obligations_where_possible ( ) ;
2160
2167
2161
2168
for ty in & self . unsolved_variables ( ) {
2162
- self . apply_fallback_if_possible ( ty) ;
2169
+ self . apply_fallback_if_possible ( ty, Fallback :: Full ) ;
2163
2170
}
2164
2171
2165
2172
let mut fulfillment_cx = self . fulfillment_cx . borrow_mut ( ) ;
@@ -4937,22 +4944,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
4937
4944
}
4938
4945
}
4939
4946
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
-
4956
4947
fn must_be_known_in_context ( & self , sp : Span , ty : Ty < ' tcx > ) -> Ty < ' tcx > {
4957
4948
if !self . is_tainted_by_errors ( ) {
4958
4949
type_error_struct ! ( self . tcx. sess, sp, ty, E0619 ,
0 commit comments