From 5954edec19c0cb35315059d91a381d24afd1d28f Mon Sep 17 00:00:00 2001 From: Aditya-PS-05 Date: Thu, 20 Nov 2025 02:06:34 +0530 Subject: [PATCH 1/4] feat: add regression test for #19957 --- .../hir-ty/src/tests/regression/new_solver.rs | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/crates/hir-ty/src/tests/regression/new_solver.rs b/crates/hir-ty/src/tests/regression/new_solver.rs index 933a9a5c3519..ef0c03803cf2 100644 --- a/crates/hir-ty/src/tests/regression/new_solver.rs +++ b/crates/hir-ty/src/tests/regression/new_solver.rs @@ -552,3 +552,53 @@ where "#]], ); } + +#[test] +fn regression_19957() { + // async-trait patterns should not produce false type mismatches between + // Pin> and Pin> + check_no_mismatches( + r#" +//- minicore: future, pin, result, error, send +use core::{future::Future, pin::Pin}; + +pub enum SimpleAsyncTraitResult { + Ok, + Error, +} + +pub struct ExampleData { + pub id: i32, + pub name: String, +} +// As we can't directly use #[async_trait] directly in tests +// This simulates what #[async_trait] expands to +pub trait SimpleAsyncTraitModel { + fn save<'life0, 'async_trait>( + &'life0 self, + ) -> Pin>> + Send + 'async_trait>> + where + 'life0: 'async_trait, + Self: 'async_trait; +} + +impl SimpleAsyncTraitModel for ExampleData { + fn save<'life0, 'async_trait>( + &'life0 self, + ) -> Pin>> + Send + 'async_trait>> + where + 'life0: 'async_trait, + Self: 'async_trait, + { + Box::pin(async move { + if self.id > 0 { + Ok(SimpleAsyncTraitResult::Ok) + } else { + Ok(SimpleAsyncTraitResult::Error) + } + }) + } +} +"#, + ); +} From 772e15e8e36c4b9676abbd23d18e9f652188405a Mon Sep 17 00:00:00 2001 From: Aditya-PS-05 Date: Thu, 20 Nov 2025 14:21:39 +0530 Subject: [PATCH 2/4] feat: update test --- .../hir-ty/src/tests/regression/new_solver.rs | 49 +++++++++++-------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/crates/hir-ty/src/tests/regression/new_solver.rs b/crates/hir-ty/src/tests/regression/new_solver.rs index ef0c03803cf2..4866a038d64a 100644 --- a/crates/hir-ty/src/tests/regression/new_solver.rs +++ b/crates/hir-ty/src/tests/regression/new_solver.rs @@ -554,49 +554,58 @@ where } #[test] +// #[should_panic(expected = "Unexpected type mismatches")] fn regression_19957() { - // async-trait patterns should not produce false type mismatches between - // Pin> and Pin> + // This test documents issue #19957: async-trait patterns incorrectly produce + // type mismatches between Pin> and Pin>. + // + // The test currently FAILS (as expected) because the bug is not yet fixed. + // When the bug is fixed, remove the #[should_panic] attribute. check_no_mismatches( r#" -//- minicore: future, pin, result, error, send +//- minicore: future, pin, result, error, send, coerce_unsized, dispatch_from_dyn use core::{future::Future, pin::Pin}; -pub enum SimpleAsyncTraitResult { - Ok, - Error, +#[lang = "owned_box"] +pub struct Box { + inner: *mut T, } +impl Box { + fn pin(value: T) -> Pin> { + // Implementation details don't matter here for type checking + loop {} + } +} + +impl, U: ?Sized> core::ops::CoerceUnsized> for Box {} + +impl, U: ?Sized> core::ops::DispatchFromDyn> for Box {} + pub struct ExampleData { pub id: i32, - pub name: String, } -// As we can't directly use #[async_trait] directly in tests -// This simulates what #[async_trait] expands to -pub trait SimpleAsyncTraitModel { + +// Simulates what #[async_trait] expands to +pub trait SimpleModel { fn save<'life0, 'async_trait>( &'life0 self, - ) -> Pin>> + Send + 'async_trait>> + ) -> Pin + Send + 'async_trait>> where 'life0: 'async_trait, Self: 'async_trait; } -impl SimpleAsyncTraitModel for ExampleData { +impl SimpleModel for ExampleData { fn save<'life0, 'async_trait>( &'life0 self, - ) -> Pin>> + Send + 'async_trait>> + ) -> Pin + Send + 'async_trait>> where 'life0: 'async_trait, Self: 'async_trait, { - Box::pin(async move { - if self.id > 0 { - Ok(SimpleAsyncTraitResult::Ok) - } else { - Ok(SimpleAsyncTraitResult::Error) - } - }) + // Body creates Pin>, which should coerce to Pin> + Box::pin(async move { self.id }) } } "#, From a63900837a3f393f382c52f6e5ced84e387bb5ce Mon Sep 17 00:00:00 2001 From: Aditya-PS-05 Date: Fri, 21 Nov 2025 10:59:14 +0530 Subject: [PATCH 3/4] remove comments --- crates/hir-ty/src/tests/regression/new_solver.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/crates/hir-ty/src/tests/regression/new_solver.rs b/crates/hir-ty/src/tests/regression/new_solver.rs index 4866a038d64a..420a316009a3 100644 --- a/crates/hir-ty/src/tests/regression/new_solver.rs +++ b/crates/hir-ty/src/tests/regression/new_solver.rs @@ -554,13 +554,11 @@ where } #[test] -// #[should_panic(expected = "Unexpected type mismatches")] fn regression_19957() { // This test documents issue #19957: async-trait patterns incorrectly produce // type mismatches between Pin> and Pin>. // // The test currently FAILS (as expected) because the bug is not yet fixed. - // When the bug is fixed, remove the #[should_panic] attribute. check_no_mismatches( r#" //- minicore: future, pin, result, error, send, coerce_unsized, dispatch_from_dyn From f39579c04e8ecafdc6843d1656c30fbc0430acd9 Mon Sep 17 00:00:00 2001 From: Aditya-PS-05 Date: Fri, 21 Nov 2025 19:05:36 +0530 Subject: [PATCH 4/4] update minicore --- crates/hir-ty/src/tests/regression/new_solver.rs | 2 -- crates/test-utils/src/minicore.rs | 6 ++++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/hir-ty/src/tests/regression/new_solver.rs b/crates/hir-ty/src/tests/regression/new_solver.rs index 420a316009a3..18509c52847f 100644 --- a/crates/hir-ty/src/tests/regression/new_solver.rs +++ b/crates/hir-ty/src/tests/regression/new_solver.rs @@ -557,8 +557,6 @@ where fn regression_19957() { // This test documents issue #19957: async-trait patterns incorrectly produce // type mismatches between Pin> and Pin>. - // - // The test currently FAILS (as expected) because the bug is not yet fixed. check_no_mismatches( r#" //- minicore: future, pin, result, error, send, coerce_unsized, dispatch_from_dyn diff --git a/crates/test-utils/src/minicore.rs b/crates/test-utils/src/minicore.rs index d5905afc3896..679fe420b05c 100644 --- a/crates/test-utils/src/minicore.rs +++ b/crates/test-utils/src/minicore.rs @@ -1518,6 +1518,12 @@ pub mod pin { { } // endregion:dispatch_from_dyn + // region:coerce_unsized + impl crate::ops::CoerceUnsized> for Pin where + Ptr: crate::ops::CoerceUnsized + { + } + // endregion:coerce_unsized } // endregion:pin