Skip to content

ExistentialTraitRef::with_self_ty gets called with escaping bound vars since a few months ago #157122

Description

@fmease

Back in March I opened PR #153497 which among other things uncommented a debug assertion that was accidentally commented out in refactoring PR #53816 all the way back in 2018 (that's 8 years ago!), see file src/librustc/ty/sty.rs in the patch set. CI was happy but then after I rebased one month later in April, CI suddenly failed since rustc@stage1 could no longer build rustc@stage2 as it now triggered the assertion when trying to compile itertools (raw logs). It would be pretty crazy if this assertion never(?) triggered for 8+ years only to start triggering one month after me opening my PR, so I don't exactly know what's going on. Honestly, I don't even know for sure if this assertion is correct in the first place, somebody please enlighten me. Otherwise this needs a bisection.

For now, I'm keeping it commented out but I'll at least add a FIXME.

Side note: By now I do know of the unimplemented but accepted MCP 433 | Introduce ty::WhereClause to align chalk and rustc dyn representation from 2021 which would considerably change the representation & API of existential entities and would probably lead to this function getting completely replaced by Binder methods but of course it's been 5 years and in any case I think it's worth investigating what's going wrong here even if all of this ends up getting rewritten.

To reproduce the ICE: Uncomment the debug_assert!(!self_ty.has_escaping_bound_vars()); in ExistentialTraitRef::with_self_ty in compiler/rustc_type_ir/src/predicate.rs. Then ./x build library --stage 2.

Activity

added
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
C-bugCategory: This is a bug.
T-typesRelevant to the types team, which will review and decide on the PR/issue.
A-dyn-traitArea: trait objects, vtable layout
on May 29, 2026
added
needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
on May 29, 2026
removed
needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
on Jun 9, 2026
added 2 commits that reference this issue on Jun 10, 2026
20c1e3f
4479111
added 6 commits that reference this issue on Jun 10, 2026
96362fc
0160a6b
8f45861
b64551d
0f3ad6b
49a638d
added a commit that references this issue on Jun 11, 2026
ea4cd49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-dyn-traitArea: trait objects, vtable layoutC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions