Skip to content

Commit 66fb34d

Browse files
Don't normalize in confirm_poly_trait_refs
1 parent e7f9e14 commit 66fb34d

File tree

1 file changed

+15
-30
lines changed

1 file changed

+15
-30
lines changed

compiler/rustc_trait_selection/src/traits/select/confirmation.rs

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,15 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
606606
.infcx
607607
.shallow_resolve(obligation.self_ty().no_bound_vars())
608608
.expect("fn pointer should not capture bound vars from predicate");
609-
let sig = self_ty.fn_sig(self.tcx());
609+
// FnDef signatures are not necessarily normalized
610+
let Normalized { value: sig, obligations: mut nested } = normalize_with_depth(
611+
self,
612+
obligation.param_env,
613+
obligation.cause.clone(),
614+
obligation.recursion_depth + 1,
615+
self_ty.fn_sig(self.tcx()),
616+
);
617+
610618
let trait_ref = closure_trait_ref_and_return_type(
611619
self.tcx(),
612620
obligation.predicate.def_id(),
@@ -616,22 +624,14 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
616624
)
617625
.map_bound(|(trait_ref, _)| trait_ref);
618626

619-
let mut nested = self.confirm_poly_trait_refs(obligation, trait_ref)?;
627+
nested.extend(self.confirm_poly_trait_refs(obligation, trait_ref)?);
620628

621629
// Confirm the `type Output: Sized;` bound that is present on `FnOnce`
622630
let cause = obligation.derived_cause(BuiltinDerivedObligation);
623-
let output_ty = self.infcx.replace_bound_vars_with_placeholders(sig.output());
624-
let output_ty = normalize_with_depth_to(
625-
self,
626-
obligation.param_env,
627-
cause.clone(),
628-
obligation.recursion_depth + 1,
629-
output_ty,
630-
&mut nested,
631-
);
632-
let tr =
633-
ty::Binder::dummy(self.tcx().at(cause.span).mk_trait_ref(LangItem::Sized, [output_ty]));
634-
nested.push(Obligation::new(self.infcx.tcx, cause, obligation.param_env, tr));
631+
let predicate = sig
632+
.output()
633+
.map_bound(|ty| self.tcx().at(cause.span).mk_trait_ref(LangItem::Sized, [ty]));
634+
nested.push(Obligation::new(self.infcx.tcx, cause, obligation.param_env, predicate));
635635

636636
Ok(ImplSourceFnPointerData { fn_ty: self_ty, nested })
637637
}
@@ -799,25 +799,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
799799
expected_trait_ref: ty::PolyTraitRef<'tcx>,
800800
) -> Result<Vec<PredicateObligation<'tcx>>, SelectionError<'tcx>> {
801801
let obligation_trait_ref = obligation.predicate.to_poly_trait_ref();
802-
// Normalize the obligation and expected trait refs together, because why not
803-
let Normalized { obligations: nested, value: (obligation_trait_ref, expected_trait_ref) } =
804-
ensure_sufficient_stack(|| {
805-
normalize_with_depth(
806-
self,
807-
obligation.param_env,
808-
obligation.cause.clone(),
809-
obligation.recursion_depth + 1,
810-
(obligation_trait_ref, expected_trait_ref),
811-
)
812-
});
813-
814802
self.infcx
815803
.at(&obligation.cause, obligation.param_env)
816804
.sup(obligation_trait_ref, expected_trait_ref)
817-
.map(|InferOk { mut obligations, .. }| {
818-
obligations.extend(nested);
819-
obligations
820-
})
805+
.map(|InferOk { value: (), obligations }| obligations)
821806
.map_err(|e| OutputTypeParameterMismatch(expected_trait_ref, obligation_trait_ref, e))
822807
}
823808

0 commit comments

Comments
 (0)