about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2024-04-23 06:24:55 +0200
committerGitHub <noreply@github.com>2024-04-23 06:24:55 +0200
commit8859631b40f8646857797d13bd9deac595d08a14 (patch)
tree9102cc8cfc7c9ab49ad3c58197f65deb6b38f2b5
parentd5cfc5c07a7f7348df32266f688c8af119438741 (diff)
parent06cd79bb5beee0b240194a80fa8930ca620ea0f5 (diff)
downloadrust-8859631b40f8646857797d13bd9deac595d08a14.tar.gz
rust-8859631b40f8646857797d13bd9deac595d08a14.zip
Rollup merge of #124057 - gurry:124031-ice-layout-errored, r=compiler-errors
Fix ICE when ADT tail has type error

Fixes #124031
-rw-r--r--compiler/rustc_middle/src/ty/layout.rs4
-rw-r--r--tests/ui/layout/ice-type-error-in-tail-124031.rs (renamed from tests/crashes/124031.rs)5
-rw-r--r--tests/ui/layout/ice-type-error-in-tail-124031.stderr12
3 files changed, 20 insertions, 1 deletions
diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs
index 6381bd190ac..897d6f5662f 100644
--- a/compiler/rustc_middle/src/ty/layout.rs
+++ b/compiler/rustc_middle/src/ty/layout.rs
@@ -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",
diff --git a/tests/crashes/124031.rs b/tests/ui/layout/ice-type-error-in-tail-124031.rs
index bdc66fbafe4..0a2be117403 100644
--- a/tests/crashes/124031.rs
+++ b/tests/ui/layout/ice-type-error-in-tail-124031.rs
@@ -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,
diff --git a/tests/ui/layout/ice-type-error-in-tail-124031.stderr b/tests/ui/layout/ice-type-error-in-tail-124031.stderr
new file mode 100644
index 00000000000..57dc83f92df
--- /dev/null
+++ b/tests/ui/layout/ice-type-error-in-tail-124031.stderr
@@ -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`.