From 95491661695dacdc3cd92c5d739695a15fe3cfea Mon Sep 17 00:00:00 2001 From: lcnr Date: Mon, 1 Dec 2025 12:47:18 +0100 Subject: [PATCH 1/2] add test --- ...und-unsatisfied-item-bounds-mit-opt-ice.rs | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 tests/ui/where-clauses/projection-bound-unsatisfied-item-bounds-mit-opt-ice.rs diff --git a/tests/ui/where-clauses/projection-bound-unsatisfied-item-bounds-mit-opt-ice.rs b/tests/ui/where-clauses/projection-bound-unsatisfied-item-bounds-mit-opt-ice.rs new file mode 100644 index 0000000000000..80eec709eecbc --- /dev/null +++ b/tests/ui/where-clauses/projection-bound-unsatisfied-item-bounds-mit-opt-ice.rs @@ -0,0 +1,25 @@ +//@ compile-flags: -Copt-level=3 --crate-type=rlib +//@ build-pass + +// A regression test for #149081. The environment of `size` and `align` +// currently means that the item bound of`T::Assoc` doesn't hold. This can +// result in normalization failures and ICE during MIR optimizations. +// +// This will no longer be an issue once #149283 is implemented. + +pub fn align, U>() -> usize { + std::mem::align_of::>() +} + +pub fn size, U>() -> usize { + std::mem::size_of::>() +} + +pub struct Wrapper { + assoc2: ::Assoc, + value: T, +} + +pub trait WithAssoc { + type Assoc: WithAssoc; +} From 02d84c8d23e3e5cf61ab0ce11cf756625b8180a8 Mon Sep 17 00:00:00 2001 From: lcnr Date: Mon, 1 Dec 2025 12:48:18 +0100 Subject: [PATCH 2/2] generic normalization errors to `TooGeneric` --- .../src/interpret/eval_context.rs | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_const_eval/src/interpret/eval_context.rs b/compiler/rustc_const_eval/src/interpret/eval_context.rs index 0e4a98f0941ac..d23369caffa42 100644 --- a/compiler/rustc_const_eval/src/interpret/eval_context.rs +++ b/compiler/rustc_const_eval/src/interpret/eval_context.rs @@ -11,7 +11,9 @@ use rustc_middle::ty::layout::{ self, FnAbiError, FnAbiOf, FnAbiOfHelpers, FnAbiRequest, LayoutError, LayoutOf, LayoutOfHelpers, TyAndLayout, }; -use rustc_middle::ty::{self, GenericArgsRef, Ty, TyCtxt, TypeFoldable, TypingEnv, Variance}; +use rustc_middle::ty::{ + self, GenericArgsRef, Ty, TyCtxt, TypeFoldable, TypeVisitableExt, TypingEnv, Variance, +}; use rustc_middle::{mir, span_bug}; use rustc_span::Span; use rustc_target::callconv::FnAbi; @@ -84,10 +86,31 @@ impl<'tcx, M: Machine<'tcx>> LayoutOfHelpers<'tcx> for InterpCx<'tcx, M> { #[inline] fn handle_layout_err( &self, - err: LayoutError<'tcx>, + mut err: LayoutError<'tcx>, _: Span, _: Ty<'tcx>, ) -> InterpErrorKind<'tcx> { + // FIXME(#149283): This is really hacky and is only used to hide type + // system bugs. We use it as a temporary fix for #149081. + // + // While it's expected that we sometimes get ambiguity errors when + // entering another generic environment while the current environment + // itself is still generic, we should never fail to entirely prove + // something. + match err { + LayoutError::NormalizationFailure(ty, _) => { + if ty.has_non_region_param() { + err = LayoutError::TooGeneric(ty); + } + } + + LayoutError::Unknown(_) + | LayoutError::SizeOverflow(_) + | LayoutError::InvalidSimd { .. } + | LayoutError::TooGeneric(_) + | LayoutError::ReferencesError(_) + | LayoutError::Cycle(_) => {} + } err_inval!(Layout(err)) } } @@ -112,7 +135,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { /// and allows wrapping the actual [LayoutOf::layout_of] with a tracing span. /// See [LayoutOf::layout_of] for the original documentation. #[inline(always)] - pub fn layout_of(&self, ty: Ty<'tcx>) -> >::LayoutOfResult { + pub fn layout_of(&self, ty: Ty<'tcx>) -> Result, InterpErrorKind<'tcx>> { let _trace = enter_trace_span!(M, layouting::layout_of, ty = ?ty.kind()); LayoutOf::layout_of(self, ty) }