Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions crates/hir-ty/src/tests/regression/new_solver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,3 +552,58 @@ where
"#]],
);
}

#[test]
fn regression_19957() {
// This test documents issue #19957: async-trait patterns incorrectly produce
// type mismatches between Pin<Box<dyn Future>> and Pin<Box<impl Future>>.
check_no_mismatches(
r#"
//- minicore: future, pin, result, error, send, coerce_unsized, dispatch_from_dyn
use core::{future::Future, pin::Pin};

#[lang = "owned_box"]
pub struct Box<T: ?Sized> {
inner: *mut T,
}

impl<T> Box<T> {
fn pin(value: T) -> Pin<Box<T>> {
// Implementation details don't matter here for type checking
loop {}
}
}

impl<T: ?Sized + core::marker::Unsize<U>, U: ?Sized> core::ops::CoerceUnsized<Box<U>> for Box<T> {}

impl<T: ?Sized + core::ops::DispatchFromDyn<U>, U: ?Sized> core::ops::DispatchFromDyn<Box<U>> for Box<T> {}

pub struct ExampleData {
pub id: i32,
}

// Simulates what #[async_trait] expands to
pub trait SimpleModel {
fn save<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = i32> + Send + 'async_trait>>
where
'life0: 'async_trait,
Self: 'async_trait;
}

impl SimpleModel for ExampleData {
fn save<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = i32> + Send + 'async_trait>>
where
'life0: 'async_trait,
Self: 'async_trait,
{
// Body creates Pin<Box<impl Future>>, which should coerce to Pin<Box<dyn Future>>
Box::pin(async move { self.id })
}
}
"#,
);
}
6 changes: 6 additions & 0 deletions crates/test-utils/src/minicore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1518,6 +1518,12 @@ pub mod pin {
{
}
// endregion:dispatch_from_dyn
// region:coerce_unsized
impl<Ptr, U> crate::ops::CoerceUnsized<Pin<U>> for Pin<Ptr> where
Ptr: crate::ops::CoerceUnsized<U>
{
}
// endregion:coerce_unsized
}
// endregion:pin

Expand Down