From 8b543ce860ed183efefbf8c7ac51680f0b1b6352 Mon Sep 17 00:00:00 2001 From: Alessio Rocchi Date: Sun, 12 Apr 2026 12:02:31 +0200 Subject: [PATCH] Add regression test for struct-to-enum change under incremental compilation The ICE (`adt_sized_constraint called on non-struct type`) was fixed indirectly by the removal of the `adt_sized_constraint` query, but no regression test was added. This adds one using the minimized reproducer from the original report. --- .../adt-sized-constraint-on-enum.rs | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 tests/incremental/adt-sized-constraint-on-enum.rs diff --git a/tests/incremental/adt-sized-constraint-on-enum.rs b/tests/incremental/adt-sized-constraint-on-enum.rs new file mode 100644 index 0000000000000..0409ef6be0199 --- /dev/null +++ b/tests/incremental/adt-sized-constraint-on-enum.rs @@ -0,0 +1,67 @@ +// Regression test for https://github.com/rust-lang/rust/issues/135287. +// Changing a struct to an enum with incremental compilation previously caused +// an ICE: `adt_sized_constraint called on non-struct type`. + +//@ revisions: cfail1 cfail2 +//@ edition: 2021 +//@ check-pass + +#![allow(dead_code)] + +use std::future::Future; +use std::marker::PhantomData; +use std::pin::Pin; +use std::task::{Context, Poll}; + +#[cfg(cfail1)] +struct SourceDocument {} + +#[cfg(cfail2)] +enum SourceDocument {} + +trait Loader { + type Value; + fn load(&self) -> impl Future; +} + +struct SourceDocumentLoader; +impl Loader for SourceDocumentLoader { + type Value = SourceDocument; + async fn load(&self) -> Self::Value { + todo!() + } +} + +struct ManualSend(T); +unsafe impl Send for ManualSend {} + +struct PendingButCovariant(PhantomData); +impl Future for PendingButCovariant { + type Output = T; + + fn poll(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll { + Poll::Pending + } +} + +struct DataLoader(T); +impl DataLoader { + async fn load_one(&self) -> ManualSend + where + T: Loader, + { + PendingButCovariant(PhantomData).await + } +} + +trait ContainerType { + fn resolve_field(&self) -> impl Future + Send; +} +impl ContainerType for () { + async fn resolve_field(&self) { + let loader = DataLoader(SourceDocumentLoader); + loader.load_one().await; + } +} + +fn main() {}