Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions tests/incremental/adt-sized-constraint-on-enum.rs
Original file line number Diff line number Diff line change
@@ -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<Output = Self::Value>;
}

struct SourceDocumentLoader;
impl Loader for SourceDocumentLoader {
type Value = SourceDocument;
async fn load(&self) -> Self::Value {
todo!()
}
}

struct ManualSend<T>(T);
unsafe impl<T: Send> Send for ManualSend<T> {}

struct PendingButCovariant<T>(PhantomData<T>);
impl<T> Future for PendingButCovariant<T> {
type Output = T;

fn poll(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Self::Output> {
Poll::Pending
}
}

struct DataLoader<T>(T);
impl<T> DataLoader<T> {
async fn load_one(&self) -> ManualSend<T::Value>
where
T: Loader,
{
PendingButCovariant(PhantomData).await
}
}

trait ContainerType {
fn resolve_field(&self) -> impl Future<Output = ()> + Send;
}
impl ContainerType for () {
async fn resolve_field(&self) {
let loader = DataLoader(SourceDocumentLoader);
loader.load_one().await;
}
}

fn main() {}
Loading