diff --git a/compiler/rustc_ty_utils/src/layout.rs b/compiler/rustc_ty_utils/src/layout.rs index bebc0707e26d..5a41e46f3a6b 100644 --- a/compiler/rustc_ty_utils/src/layout.rs +++ b/compiler/rustc_ty_utils/src/layout.rs @@ -777,7 +777,9 @@ fn layout_of_uncached<'tcx>( let err = if ty.has_param() || !cx.typing_env.param_env.caller_bounds().is_empty() { LayoutError::TooGeneric(ty) } else { - unreachable!("invalid rigid alias in layout_of after normalization: {ty:?}"); + LayoutError::ReferencesError(cx.tcx().dcx().delayed_bug(format!( + "unexpected rigid alias in layout_of after normalization: {ty:?}" + ))) }; return Err(error(cx, err)); } diff --git a/tests/ui/layout/rigid-alias-due-to-broken-impl.stderr b/tests/ui/layout/rigid-alias-due-to-broken-impl.stderr new file mode 100644 index 000000000000..e9ba6df2fdc7 --- /dev/null +++ b/tests/ui/layout/rigid-alias-due-to-broken-impl.stderr @@ -0,0 +1,12 @@ +error[E0046]: not all trait items implemented, missing: `Assoc` + --> $DIR/rigid-alias-due-to-broken-impl.rs:14:1 + | +LL | type Assoc; + | ---------- `Assoc` from trait +... +LL | impl Foo for str {} + | ^^^^^^^^^^^^^^^^ missing `Assoc` in implementation + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0046`.