From ca8316ff3a476dd887a7e5471522dadf29f62d48 Mon Sep 17 00:00:00 2001 From: Raghavender Singh Date: Mon, 6 Apr 2026 19:02:15 +0530 Subject: [PATCH] Fix ICE in ptr_metadata_ty_or_tail for recursive associated types --- compiler/rustc_middle/src/ty/sty.rs | 5 ++-- ...etadata-recursive-assoc-type-ice-153431.rs | 24 +++++++++++++++++++ ...ata-recursive-assoc-type-ice-153431.stderr | 17 +++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 tests/ui/associated-types/ptr-metadata-recursive-assoc-type-ice-153431.rs create mode 100644 tests/ui/associated-types/ptr-metadata-recursive-assoc-type-ice-153431.stderr diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index 0e0715a8861bc..86dadb6c5c604 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -1769,8 +1769,9 @@ impl<'tcx> Ty<'tcx> { | ty::UnsafeBinder(_) => todo!("FIXME(unsafe_binder)"), - ty::Infer(ty::TyVar(_)) - | ty::Pat(..) + ty::Infer(ty::TyVar(_)) => Ok(tcx.types.unit), + + ty::Pat(..) | ty::Bound(..) | ty::Placeholder(..) | ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => bug!( diff --git a/tests/ui/associated-types/ptr-metadata-recursive-assoc-type-ice-153431.rs b/tests/ui/associated-types/ptr-metadata-recursive-assoc-type-ice-153431.rs new file mode 100644 index 0000000000000..86f7fe94489c7 --- /dev/null +++ b/tests/ui/associated-types/ptr-metadata-recursive-assoc-type-ice-153431.rs @@ -0,0 +1,24 @@ +// Regression test for . +// Used to ICE in `ptr_metadata_ty_or_tail` when computing pointer metadata +// for a struct whose tail field has a recursive associated type. +//~^^^ ERROR overflow evaluating the requirement `::Assoc2 == _` + +trait Trait { + type Assoc2; +} + +struct Bar; +impl Trait for Bar { + type Assoc2 = Result<(), ::Assoc2>; + //~^ ERROR overflow evaluating the requirement `::Assoc2 == _` +} + +struct Foo { + field: ::Assoc2, + //~^ ERROR overflow evaluating the requirement `::Assoc2 == _` +} + +static BAR: u8 = 42; +static FOO2: &Foo = unsafe { std::mem::transmute(&BAR) }; + +fn main() {} diff --git a/tests/ui/associated-types/ptr-metadata-recursive-assoc-type-ice-153431.stderr b/tests/ui/associated-types/ptr-metadata-recursive-assoc-type-ice-153431.stderr new file mode 100644 index 0000000000000..7434e88389420 --- /dev/null +++ b/tests/ui/associated-types/ptr-metadata-recursive-assoc-type-ice-153431.stderr @@ -0,0 +1,17 @@ +error[E0275]: overflow evaluating the requirement `::Assoc2 == _` + --> $DIR/ptr-metadata-recursive-assoc-type-ice-153431.rs:12:19 + | +LL | type Assoc2 = Result<(), ::Assoc2>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error[E0275]: overflow evaluating the requirement `::Assoc2 == _` + --> $DIR/ptr-metadata-recursive-assoc-type-ice-153431.rs:17:12 + | +LL | field: ::Assoc2, + | ^^^^^^^^^^^^^^^^^^^^^^ + +error[E0275]: overflow evaluating the requirement `::Assoc2 == _` + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0275`.