Skip to content

Commit f3cd4a7

Browse files
committed
Refactor away fn default_type_parameters
It had only one caller.
1 parent 3d83fc9 commit f3cd4a7

File tree

1 file changed

+17
-29
lines changed
  • src/librustc_typeck/check

1 file changed

+17
-29
lines changed

src/librustc_typeck/check/mod.rs

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2127,34 +2127,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
21272127
}
21282128
}
21292129

2130-
/// Apply "fallbacks" to some types
2131-
/// unconstrained types get replaced with ! or () (depending on whether
2132-
/// feature(never_type) is enabled), unconstrained ints with i32, and
2133-
/// unconstrained floats with f64.
2134-
fn default_type_parameters(&self) {
2135-
// Defaulting inference variables becomes very dubious if we have
2136-
// encountered type-checking errors. Therefore, if we think we saw
2137-
// some errors in this function, just resolve all uninstanted type
2138-
// varibles to TyError.
2139-
if self.is_tainted_by_errors() {
2140-
for ty in &self.unsolved_variables() {
2141-
if let ty::TyInfer(_) = self.shallow_resolve(ty).sty {
2142-
debug!("default_type_parameters: defaulting `{:?}` to error", ty);
2143-
self.demand_eqtype(syntax_pos::DUMMY_SP, *ty, self.tcx().types.err);
2144-
}
2145-
}
2146-
return;
2147-
}
2148-
2149-
for ty in &self.unsolved_variables() {
2150-
let resolved = self.resolve_type_vars_if_possible(ty);
2151-
if resolved.is_ty_infer() {
2152-
self.apply_diverging_fallback_to_type(ty);
2153-
self.apply_numeric_fallback_to_type(ty);
2154-
}
2155-
}
2156-
}
2157-
21582130
fn apply_diverging_fallback_to_type(&self, ty: Ty<'tcx>) {
21592131
assert!(ty.is_ty_infer());
21602132
if self.type_var_diverges(ty) {
@@ -2185,7 +2157,23 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
21852157
assert!(self.deferred_call_resolutions.borrow().is_empty());
21862158

21872159
self.select_obligations_where_possible();
2188-
self.default_type_parameters();
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+
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+
}
2176+
}
21892177

21902178
let mut fulfillment_cx = self.fulfillment_cx.borrow_mut();
21912179

0 commit comments

Comments
 (0)