Skip to content

Commit 06cd79b

Browse files
committed
Fix ICE when ADT tail has type error
1 parent fb89862 commit 06cd79b

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

compiler/rustc_middle/src/ty/layout.rs

+4
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,10 @@ impl<'tcx> SizeSkeleton<'tcx> {
338338
debug_assert!(tail.has_non_region_param());
339339
Ok(SizeSkeleton::Pointer { non_zero, tail: tcx.erase_regions(tail) })
340340
}
341+
ty::Error(guar) => {
342+
// Fixes ICE #124031
343+
return Err(tcx.arena.alloc(LayoutError::ReferencesError(*guar)));
344+
}
341345
_ => bug!(
342346
"SizeSkeleton::compute({ty}): layout errored ({err:?}), yet \
343347
tail `{tail}` is not a type parameter or a projection",

tests/crashes/124031.rs renamed to tests/ui/layout/ice-type-error-in-tail-124031.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
//@ known-bug: #124031
1+
// Regression test for issue #124031
2+
// Checks that we don't ICE when the tail
3+
// of an ADT has a type error
24

35
trait Trait {
46
type RefTarget;
57
}
68

79
impl Trait for () {}
10+
//~^ ERROR not all trait items implemented, missing: `RefTarget`
811

912
struct Other {
1013
data: <() as Trait>::RefTarget,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0046]: not all trait items implemented, missing: `RefTarget`
2+
--> $DIR/ice-type-error-in-tail-124031.rs:9:1
3+
|
4+
LL | type RefTarget;
5+
| -------------- `RefTarget` from trait
6+
...
7+
LL | impl Trait for () {}
8+
| ^^^^^^^^^^^^^^^^^ missing `RefTarget` 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)