Skip to content

Properly track the depth when expanding free alias types #143744

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
Jul 11, 2025
Merged
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions compiler/rustc_middle/src/ty/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1052,9 +1052,11 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for FreeAliasTypeExpander<'tcx> {
}

self.depth += 1;
ensure_sufficient_stack(|| {
let ty = ensure_sufficient_stack(|| {
self.tcx.type_of(alias.def_id).instantiate(self.tcx, alias.args).fold_with(self)
})
});
self.depth -= 1;
ty
}

fn fold_const(&mut self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> {
Expand Down
20 changes: 20 additions & 0 deletions tests/ui/lazy-type-alias/deep-expansion.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// In several type analysis passes we employ a specialized expansion procedure.
// This procedure used to incorrectly track expansion depth (growing much faster
// than normalization depth) resulting in its internal assertion triggering.
//
// issue: <https://github.com/rust-lang/rust/issues/142419>
//@ check-pass
#![feature(lazy_type_alias)]
#![expect(incomplete_features)]

type T0 = (T1, T1, T1, T1);
type T1 = (T2, T2, T2, T2);
type T2 = (T3, T3, T3, T3);
type T3 = (T4, T4, T4, T4);
type T4 = (T5, T5, T5, T5);
type T5 = (T6, T6, T6, T6);
type T6 = (T7, T7, T7, T7);
type T7 = ();

fn accept(_: T0) {}
fn main() {}
Loading