Skip to content
/ rust Public
forked from rust-lang/rust

Commit 8125a56

Browse files
authored
Rollup merge of rust-lang#152575 - lcnr:layout-error-to-delayed-bug, r=jackh726
layout_of unexpected rigid alias delayed bug fixes rust-lang#152545. The trait solver can keep aliases as rigid even if they are not well-formed https://github.com/rust-lang/rust/blob/d7daac06d87e1252d10eaa44960164faac46beff/compiler/rustc_next_trait_solver/src/solve/normalizes_to/mod.rs#L315-L345 r? types
2 parents 22f973d + b3d9fbc commit 8125a56

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

compiler/rustc_ty_utils/src/layout.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,9 @@ fn layout_of_uncached<'tcx>(
777777
let err = if ty.has_param() || !cx.typing_env.param_env.caller_bounds().is_empty() {
778778
LayoutError::TooGeneric(ty)
779779
} else {
780-
unreachable!("invalid rigid alias in layout_of after normalization: {ty:?}");
780+
LayoutError::ReferencesError(cx.tcx().dcx().delayed_bug(format!(
781+
"unexpected rigid alias in layout_of after normalization: {ty:?}"
782+
)))
781783
};
782784
return Err(error(cx, err));
783785
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Make sure we don't ICE if `layout_of` encounters an alias
2+
// which is rigid due to a malformed program. A regression test
3+
// for #152545.
4+
//
5+
// This specific ICE happens in the `KnownPanicsLint` visitor.
6+
7+
//@ compile-flags: --crate-type=rlib
8+
trait Foo {
9+
type Assoc;
10+
}
11+
12+
// The trait solver only treats missng associated items
13+
// as rigid if the self-type is known to be unsized.
14+
impl Foo for str {}
15+
//~^ ERROR not all trait items implemented
16+
17+
fn foo(_: [u32; std::mem::size_of::<<str as Foo>::Assoc>()]) {}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0046]: not all trait items implemented, missing: `Assoc`
2+
--> $DIR/rigid-alias-due-to-broken-impl.rs:14:1
3+
|
4+
LL | type Assoc;
5+
| ---------- `Assoc` from trait
6+
...
7+
LL | impl Foo for str {}
8+
| ^^^^^^^^^^^^^^^^ missing `Assoc` in implementation
9+
10+
error: aborting due to 1 previous error
11+
12+
For more information about this error, try `rustc --explain E0046`.

0 commit comments

Comments
 (0)