@@ -2127,23 +2127,23 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
2127
2127
}
2128
2128
}
2129
2129
2130
- fn apply_diverging_fallback_to_type ( & self , ty : Ty < ' tcx > ) {
2131
- assert ! ( ty. is_ty_infer( ) ) ;
2132
- if self . type_var_diverges ( ty) {
2133
- debug ! ( "default_type_parameters: defaulting `{:?}` to `!` because it diverges" , ty) ;
2134
- self . demand_eqtype ( syntax_pos:: DUMMY_SP , ty, self . tcx . mk_diverging_default ( ) ) ;
2135
- }
2136
- }
2137
-
2138
- fn apply_numeric_fallback_to_type ( & self , ty : Ty < ' tcx > ) {
2130
+ // Tries to apply a fallback to `ty` if it is an unsolved variable.
2131
+ // Non-numerics get replaced with ! or () (depending on whether
2132
+ // feature(never_type) is enabled), unconstrained ints with i32,
2133
+ // unconstrained floats with f64.
2134
+ // Defaulting inference variables becomes very dubious if we have
2135
+ // encountered type-checking errors. In that case, fallback to TyError.
2136
+ fn apply_fallback_if_possible ( & self , ty : Ty < ' tcx > ) {
2139
2137
use rustc:: ty:: error:: UnconstrainedNumeric :: Neither ;
2140
2138
use rustc:: ty:: error:: UnconstrainedNumeric :: { UnconstrainedInt , UnconstrainedFloat } ;
2141
2139
2142
2140
assert ! ( ty. is_ty_infer( ) ) ;
2143
2141
let fallback = match self . type_is_unconstrained_numeric ( ty) {
2142
+ _ if self . is_tainted_by_errors ( ) => self . tcx ( ) . types . err ,
2144
2143
UnconstrainedInt => self . tcx . types . i32 ,
2145
2144
UnconstrainedFloat => self . tcx . types . f64 ,
2146
- Neither => return ,
2145
+ Neither if self . type_var_diverges ( ty) => self . tcx . mk_diverging_default ( ) ,
2146
+ Neither => return
2147
2147
} ;
2148
2148
debug ! ( "default_type_parameters: defaulting `{:?}` to `{:?}`" , ty, fallback) ;
2149
2149
self . demand_eqtype ( syntax_pos:: DUMMY_SP , ty, fallback) ;
@@ -2158,21 +2158,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
2158
2158
2159
2159
self . select_obligations_where_possible ( ) ;
2160
2160
2161
- // Apply fallbacks to unsolved variables.
2162
- // Non-numerics get replaced with ! or () (depending on whether
2163
- // feature(never_type) is enabled), unconstrained ints with i32,
2164
- // unconstrained floats with f64.
2165
2161
for ty in & self . unsolved_variables ( ) {
2166
- if self . is_tainted_by_errors ( ) {
2167
- // Defaulting inference variables becomes very dubious if we have
2168
- // encountered type-checking errors. In that case,
2169
- // just resolve all uninstanted type variables to TyError.
2170
- debug ! ( "default_type_parameters: defaulting `{:?}` to error" , ty) ;
2171
- self . demand_eqtype ( syntax_pos:: DUMMY_SP , * ty, self . tcx ( ) . types . err ) ;
2172
- } else {
2173
- self . apply_diverging_fallback_to_type ( ty) ;
2174
- self . apply_numeric_fallback_to_type ( ty) ;
2175
- }
2162
+ self . apply_fallback_if_possible ( ty) ;
2176
2163
}
2177
2164
2178
2165
let mut fulfillment_cx = self . fulfillment_cx . borrow_mut ( ) ;
@@ -4942,18 +4929,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
4942
4929
// If no resolution is possible, then an error is reported.
4943
4930
// Numeric inference variables may be left unresolved.
4944
4931
pub fn structurally_resolved_type ( & self , sp : Span , ty : Ty < ' tcx > ) -> Ty < ' tcx > {
4945
- let mut ty = self . resolve_type_vars_with_obligations ( ty) ;
4932
+ let ty = self . resolve_type_vars_with_obligations ( ty) ;
4946
4933
if !ty. is_ty_var ( ) {
4947
4934
ty
4948
4935
} else {
4949
- // Try divering fallback.
4950
- self . apply_diverging_fallback_to_type ( ty) ;
4951
- ty = self . resolve_type_vars_with_obligations ( ty) ;
4952
- if !ty. is_ty_var ( ) {
4953
- ty
4954
- } else { // Fallback failed, error.
4955
- self . must_be_known_in_context ( sp, ty)
4956
- }
4936
+ self . must_be_known_in_context ( sp, ty)
4957
4937
}
4958
4938
}
4959
4939
@@ -4963,9 +4943,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
4963
4943
if !ty. is_ty_infer ( ) {
4964
4944
return ty;
4965
4945
} else {
4966
- // Try diverging or numeric fallback.
4967
- self . apply_diverging_fallback_to_type ( ty) ;
4968
- self . apply_numeric_fallback_to_type ( ty) ;
4946
+ self . apply_fallback_if_possible ( ty) ;
4969
4947
ty = self . resolve_type_vars_with_obligations ( ty) ;
4970
4948
if !ty. is_ty_infer ( ) {
4971
4949
ty
0 commit comments