Merge pull request #21069 from Aditya-PS-05/feat/add-regression-test-19957

feat: add test for async-trait type mismatch
This commit is contained in:
Shoyu Vanilla (Flint) 2025-11-21 16:09:42 +00:00 committed by GitHub
commit db70ac9369
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 61 additions and 0 deletions

View file

@ -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 })
}
}
"#,
);
}

View file

@ -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