Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ICE when ADT tail has type error #124057

Merged
merged 1 commit into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions compiler/rustc_middle/src/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,10 @@ impl<'tcx> SizeSkeleton<'tcx> {
debug_assert!(tail.has_non_region_param());
Ok(SizeSkeleton::Pointer { non_zero, tail: tcx.erase_regions(tail) })
}
ty::Error(guar) => {
// Fixes ICE #124031
return Err(tcx.arena.alloc(LayoutError::ReferencesError(*guar)));
}
_ => bug!(
"SizeSkeleton::compute({ty}): layout errored ({err:?}), yet \
tail `{tail}` is not a type parameter or a projection",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
//@ known-bug: #124031
// Regression test for issue #124031
// Checks that we don't ICE when the tail
// of an ADT has a type error

trait Trait {
type RefTarget;
}

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

struct Other {
data: <() as Trait>::RefTarget,
Expand Down
12 changes: 12 additions & 0 deletions tests/ui/layout/ice-type-error-in-tail-124031.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
error[E0046]: not all trait items implemented, missing: `RefTarget`
--> $DIR/ice-type-error-in-tail-124031.rs:9:1
|
LL | type RefTarget;
| -------------- `RefTarget` from trait
...
LL | impl Trait for () {}
| ^^^^^^^^^^^^^^^^^ missing `RefTarget` in implementation

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0046`.