Skip to content

Commit 142a420

Browse files
authored
Rollup merge of #163100 - lcnr:closure-sig-inference, r=adwinwhite
normalize normalizes, avoid next-solver hack we changed normalization to actually normalize with the new solver, this is now unnecessary :> r? adwinwhite or sth
2 parents c85cbf5 + 1e9b3bc commit 142a420

1 file changed

Lines changed: 2 additions & 38 deletions

File tree

‎compiler/rustc_hir_typeck/src/closure.rs‎

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -385,44 +385,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
385385
}
386386
}
387387

388-
// Don't infer a closure signature from a goal that names the closure type as this will
389-
// (almost always) lead to occurs check errors later in type checking.
390-
if self.next_trait_solver()
391-
&& let Some(inferred_sig) = inferred_sig
392-
{
393-
// In the new solver it is difficult to explicitly normalize the inferred signature as we
394-
// would have to manually handle universes and rewriting bound vars and placeholders back
395-
// and forth.
396-
//
397-
// Instead we take advantage of the fact that we relating an inference variable with an alias
398-
// will only instantiate the variable if the alias is rigid(*not quite). Concretely we:
399-
// - Create some new variable `?sig`
400-
// - Equate `?sig` with the unnormalized signature, e.g. `fn(<Foo<?x> as Trait>::Assoc)`
401-
// - Depending on whether `<Foo<?x> as Trait>::Assoc` is rigid, ambiguous or normalizeable,
402-
// we will either wind up with `?sig=<Foo<?x> as Trait>::Assoc/?y/ConcreteTy` respectively.
403-
//
404-
// *: In cases where there are ambiguous aliases in the signature that make use of bound vars
405-
// they will wind up present in `?sig` even though they are non-rigid.
406-
//
407-
// This is a bit weird and means we may wind up discarding the goal due to it naming `expected_ty`
408-
// even though the normalized form may not name `expected_ty`. However, this matches the existing
409-
// behaviour of the old solver and would be technically a breaking change to fix.
410-
let generalized_fnptr_sig = self.next_ty_var(span);
411-
let inferred_fnptr_sig = Ty::new_fn_ptr(self.tcx, inferred_sig.sig);
412-
self.demand_eqtype(span, inferred_fnptr_sig, generalized_fnptr_sig);
413-
414-
let resolved_sig = self.deeply_resolve_ignoring_regions(generalized_fnptr_sig);
415-
416-
if resolved_sig.visit_with(&mut MentionsTy { expected_ty }).is_continue() {
417-
expected_sig = Some(ExpectedSig {
418-
cause_span: inferred_sig.cause_span,
419-
sig: resolved_sig.fn_sig(self.tcx),
420-
});
421-
}
422-
} else {
423-
if inferred_sig.visit_with(&mut MentionsTy { expected_ty }).is_continue() {
424-
expected_sig = inferred_sig;
425-
}
388+
if inferred_sig.visit_with(&mut MentionsTy { expected_ty }).is_continue() {
389+
expected_sig = inferred_sig;
426390
}
427391
}
428392

0 commit comments

Comments
 (0)