Skip to content

Commit bdfddb3

Browse files
committed
Fix ICE when ADT tail has type error
1 parent 7e3ba5b commit bdfddb3

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

compiler/rustc_middle/src/ty/layout.rs

+6
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,12 @@ impl<'tcx> SizeSkeleton<'tcx> {
331331
ty::Ref(_, pointee, _) | ty::RawPtr(pointee, _) => {
332332
let non_zero = !ty.is_unsafe_ptr();
333333
let tail = tcx.struct_tail_erasing_lifetimes(pointee, param_env);
334+
335+
// Check if tail has type error. Fixes ICE #124031
336+
if let Err(guar) = tail.error_reported() {
337+
return Err(tcx.arena.alloc(LayoutError::ReferencesError(guar)));
338+
}
339+
334340
match tail.kind() {
335341
ty::Param(_) | ty::Alias(ty::Projection | ty::Inherent, _) => {
336342
debug_assert!(tail.has_non_region_param());
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Regression test for issue #124031
2+
// Checks that we don't ICE when the tail
3+
// of an ADT has a type error
4+
5+
trait Trait {
6+
type RefTarget;
7+
}
8+
9+
impl Trait for () {}
10+
//~^ ERROR not all trait items implemented, missing: `RefTarget`
11+
12+
struct Other {
13+
data: <() as Trait>::RefTarget,
14+
}
15+
16+
fn main() {
17+
unsafe {
18+
std::mem::transmute::<Option<()>, Option<&Other>>(None);
19+
}
20+
}
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)