Skip to content

Commit 02d84c8

Browse files
committed
generic normalization errors to TooGeneric
1 parent 9549166 commit 02d84c8

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

compiler/rustc_const_eval/src/interpret/eval_context.rs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ use rustc_middle::ty::layout::{
1111
self, FnAbiError, FnAbiOf, FnAbiOfHelpers, FnAbiRequest, LayoutError, LayoutOf,
1212
LayoutOfHelpers, TyAndLayout,
1313
};
14-
use rustc_middle::ty::{self, GenericArgsRef, Ty, TyCtxt, TypeFoldable, TypingEnv, Variance};
14+
use rustc_middle::ty::{
15+
self, GenericArgsRef, Ty, TyCtxt, TypeFoldable, TypeVisitableExt, TypingEnv, Variance,
16+
};
1517
use rustc_middle::{mir, span_bug};
1618
use rustc_span::Span;
1719
use rustc_target::callconv::FnAbi;
@@ -84,10 +86,31 @@ impl<'tcx, M: Machine<'tcx>> LayoutOfHelpers<'tcx> for InterpCx<'tcx, M> {
8486
#[inline]
8587
fn handle_layout_err(
8688
&self,
87-
err: LayoutError<'tcx>,
89+
mut err: LayoutError<'tcx>,
8890
_: Span,
8991
_: Ty<'tcx>,
9092
) -> InterpErrorKind<'tcx> {
93+
// FIXME(#149283): This is really hacky and is only used to hide type
94+
// system bugs. We use it as a temporary fix for #149081.
95+
//
96+
// While it's expected that we sometimes get ambiguity errors when
97+
// entering another generic environment while the current environment
98+
// itself is still generic, we should never fail to entirely prove
99+
// something.
100+
match err {
101+
LayoutError::NormalizationFailure(ty, _) => {
102+
if ty.has_non_region_param() {
103+
err = LayoutError::TooGeneric(ty);
104+
}
105+
}
106+
107+
LayoutError::Unknown(_)
108+
| LayoutError::SizeOverflow(_)
109+
| LayoutError::InvalidSimd { .. }
110+
| LayoutError::TooGeneric(_)
111+
| LayoutError::ReferencesError(_)
112+
| LayoutError::Cycle(_) => {}
113+
}
91114
err_inval!(Layout(err))
92115
}
93116
}
@@ -112,7 +135,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
112135
/// and allows wrapping the actual [LayoutOf::layout_of] with a tracing span.
113136
/// See [LayoutOf::layout_of] for the original documentation.
114137
#[inline(always)]
115-
pub fn layout_of(&self, ty: Ty<'tcx>) -> <Self as LayoutOfHelpers<'tcx>>::LayoutOfResult {
138+
pub fn layout_of(&self, ty: Ty<'tcx>) -> Result<TyAndLayout<'tcx>, InterpErrorKind<'tcx>> {
116139
let _trace = enter_trace_span!(M, layouting::layout_of, ty = ?ty.kind());
117140
LayoutOf::layout_of(self, ty)
118141
}

0 commit comments

Comments
 (0)