Instantiate closure-like bounds with placeholders to deal with binders correctly

This commit is contained in:
Michael Goulet 2024-03-09 22:12:33 +00:00
parent dd5e502d4b
commit 5f59b7f763
3 changed files with 139 additions and 82 deletions

View file

@ -2679,26 +2679,18 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
#[instrument(skip(self), level = "debug")]
fn closure_trait_ref_unnormalized(
&mut self,
obligation: &PolyTraitObligation<'tcx>,
args: GenericArgsRef<'tcx>,
self_ty: Ty<'tcx>,
fn_trait_def_id: DefId,
fn_host_effect: ty::Const<'tcx>,
) -> ty::PolyTraitRef<'tcx> {
let ty::Closure(_, args) = *self_ty.kind() else {
bug!("expected closure, found {self_ty}");
};
let closure_sig = args.as_closure().sig();
debug!(?closure_sig);
// NOTE: The self-type is an unboxed closure type and hence is
// in fact unparameterized (or at least does not reference any
// regions bound in the obligation).
let self_ty = obligation
.predicate
.self_ty()
.no_bound_vars()
.expect("unboxed closure type should not capture bound vars from the predicate");
closure_trait_ref_and_return_type(
self.tcx(),
obligation.predicate.def_id(),
fn_trait_def_id,
self_ty,
closure_sig,
util::TupleArgumentsFlag::No,