Skip to content

Document why we allow escaping bound vars in LTA norm #141363

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 22, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions compiler/rustc_trait_selection/src/traits/normalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,12 +299,21 @@ impl<'a, 'b, 'tcx> AssocTypeNormalizer<'a, 'b, 'tcx> {
);
}

// We don't replace bound vars in the generic arguments of the free alias with
// placeholders. This doesn't cause any issues as instantiating parameters with
// bound variables is special-cased to rewrite the debruijn index to be higher
// whenever we fold through a binder.
//
// However, we do replace any escaping bound vars in the resulting goals with
// placeholders as the trait solver does not expect to encounter escaping bound
// vars in obligations.
//
// FIXME(lazy_type_alias): Check how much this actually matters for perf before
// stabilization. This is a bit weird and generally not how we handle binders in
// the compiler so ideally we'd do the same boundvar->placeholder->boundvar dance
// that other kinds of normalization do.
let infcx = self.selcx.infcx;
self.obligations.extend(
// FIXME(BoxyUwU):
// FIXME(lazy_type_alias):
// It seems suspicious to instantiate the predicates with arguments that might be bound vars,
// we might wind up instantiating one of these bound vars underneath a hrtb.
infcx.tcx.predicates_of(free.def_id).instantiate_own(infcx.tcx, free.args).map(
|(mut predicate, span)| {
if free.has_escaping_bound_vars() {
Expand Down
Loading