Skip to content

Commit f5acf22

Browse files
committed
fix fudging
1 parent fda5795 commit f5acf22

File tree

1 file changed

+32
-33
lines changed
  • compiler/rustc_hir_typeck/src/fn_ctxt

1 file changed

+32
-33
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,38 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
235235
self.check_place_expr_if_unsized(fn_input_ty, arg_expr);
236236
}
237237

238+
let formal_input_tys_ns;
239+
let formal_input_tys = if self.next_trait_solver() {
240+
// In the new solver, the normalizations are done lazily.
241+
// Because of this, if we encounter unnormalized alias types inside this
242+
// fudge scope, we might lose the relationships between them and other vars
243+
// when fudging inference variables created here.
244+
// So, we utilize generalization to normalize aliases by adding a new
245+
// inference var and equating it with the type we want to pull out of the
246+
// fudge scope.
247+
formal_input_tys_ns = formal_input_tys
248+
.iter()
249+
.map(|&ty| {
250+
// If we replace a (unresolved) inference var with a new inference
251+
// var, it will be eventually resolved to itself and this will
252+
// weaken type inferences as the new inference var will be fudged
253+
// out and lose all relationships with other vars while the former
254+
// will not be fudged.
255+
if ty.is_ty_var() {
256+
return ty;
257+
}
258+
259+
let generalized_ty = self.next_ty_var(call_span);
260+
self.demand_eqtype(call_span, ty, generalized_ty);
261+
generalized_ty
262+
})
263+
.collect_vec();
264+
265+
formal_input_tys_ns.as_slice()
266+
} else {
267+
formal_input_tys
268+
};
269+
238270
// First, let's unify the formal method signature with the expectation eagerly.
239271
// We use this to guide coercion inference; it's output is "fudged" which means
240272
// any remaining type variables are assigned to new, unrelated variables. This
@@ -257,39 +289,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
257289
// No argument expectations are produced if unification fails.
258290
let origin = self.misc(call_span);
259291
ocx.sup(&origin, self.param_env, expected_output, formal_output)?;
260-
261-
let formal_input_tys_ns;
262-
let formal_input_tys = if self.next_trait_solver() {
263-
// In the new solver, the normalizations are done lazily.
264-
// Because of this, if we encounter unnormalized alias types inside this
265-
// fudge scope, we might lose the relationships between them and other vars
266-
// when fudging inference variables created here.
267-
// So, we utilize generalization to normalize aliases by adding a new
268-
// inference var and equating it with the type we want to pull out of the
269-
// fudge scope.
270-
formal_input_tys_ns = formal_input_tys
271-
.iter()
272-
.map(|&ty| {
273-
// If we replace a (unresolved) inference var with a new inference
274-
// var, it will be eventually resolved to itself and this will
275-
// weaken type inferences as the new inference var will be fudged
276-
// out and lose all relationships with other vars while the former
277-
// will not be fudged.
278-
if ty.is_ty_var() {
279-
return ty;
280-
}
281-
282-
let generalized_ty = self.next_ty_var(call_span);
283-
ocx.eq(&origin, self.param_env, ty, generalized_ty).unwrap();
284-
generalized_ty
285-
})
286-
.collect_vec();
287-
288-
formal_input_tys_ns.as_slice()
289-
} else {
290-
formal_input_tys
291-
};
292-
293292
if !ocx.try_evaluate_obligations().is_empty() {
294293
return Err(TypeError::Mismatch);
295294
}

0 commit comments

Comments
 (0)