Skip to content

Conversation

@Aditya-PS-05
Copy link
Contributor

@Aditya-PS-05 Aditya-PS-05 commented Nov 19, 2025

closes #19957 (remaining part)

Made a test to verify that issue #19957 is resolved. The test passes successfully, confirming that the async-trait type mismatch issue has been fixed by the migration to the new trait solver (commit d1288f6).

About Test

As we can't directly use #[async_trait] in hir-ty tests (it's not available in minicore), the test simulates what the #[async_trait] macro expands to.

The test verifies that no type mismatch occurs between the Pin<Box<dyn Future>> signature and the Pin<Box<impl Future>> returned by the async block.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 19, 2025
@rustbot
Copy link
Collaborator

rustbot commented Nov 19, 2025

⚠️ Warning ⚠️

  • There are issue links (such as #123) in the commit messages of the following commits.
    Please move them to the PR description, to avoid spamming the issues with references to the commit, and so this bot can automatically canonicalize them to avoid issues with subtree.

@Aditya-PS-05 Aditya-PS-05 changed the title feat: add test for #19957 feat: add test for async-trait type mismatch Nov 19, 2025
pub trait SimpleAsyncTraitModel {
fn save<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<SimpleAsyncTraitResult, Box<dyn core::error::Error + Send + Sync>>> + Send + 'async_trait>>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't gonna work since we have no Box in our minicore. So, it won't cause mismatch even if the issue exists in the real world, as we don't emit type mismatches for unknown types. And it would be good if you could check that the same test code fails on the past version.

@Aditya-PS-05
Copy link
Contributor Author

Aditya-PS-05 commented Nov 20, 2025

When I tested on three commits,

Test file;

#[test]
// #[should_panic(expected = "Unexpected type mismatches")]
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>>.
    //
    // The test currently FAILS 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
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 })
    }
}
"#,
    );
}

1.) On 2b2d9d8 (it's a commit before d1288f6)

Result:

   Compiling hir-ty v0.0.0 (/tmp/test-old/crates/hir-ty)
    Finished `test` profile [unoptimized + debuginfo] target(s) in 46.78s
     Running unittests src/lib.rs (target/debug/deps/hir_ty-b1d8e0b478de4a85)

running 1 test
test tests::regression::new_solver::regression_19957 ... FAILED

failures:

---- tests::regression::new_solver::regression_19957 stdout ----

thread 'tests::regression::new_solver::regression_19957' (124130) panicked at crates/hir-ty/src/tests/regression/new_solver.rs:564:5:
Unexpected type mismatches:
1109..1141: expected Pin<Box<dyn Future<Output = i32> + Send + 'async_trait>>, got Pin<Box<impl Future<Output = i32>>>

note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


failures:
    tests::regression::new_solver::regression_19957

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 917 filtered out; finished in 0.07s

error: test failed, to rerun pass `-p hir-ty --lib`

2.) On d1288f6 commit (this is the commit where the new solver trait was implemented)

Result:

   Compiling hir-ty v0.0.0 (/tmp/test-old/crates/hir-ty)
    Finished `test` profile [unoptimized + debuginfo] target(s) in 48.29s
     Running unittests src/lib.rs (target/debug/deps/hir_ty-b1d8e0b478de4a85)

running 1 test
test tests::regression::new_solver::regression_19957 ... FAILED

failures:

---- tests::regression::new_solver::regression_19957 stdout ----

thread 'tests::regression::new_solver::regression_19957' (139607) panicked at crates/hir-ty/src/tests.rs:246:9:
Unexpected type mismatches:
1109..1141: expected Pin<Box<dyn Future<Output = i32> + Send + 'async_trait>>, got Pin<Box<impl Future<Output = i32>>>

note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


failures:
    tests::regression::new_solver::regression_19957

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 916 filtered out; finished in 0.07s

error: test failed, to rerun pass `-p hir-ty --lib`
  1. On the latest commit

Result:

   Compiling hir-ty v0.0.0 (/tmp/test-old/crates/hir-ty)
    Finished `test` profile [unoptimized + debuginfo] target(s) in 46.58s
     Running unittests src/lib.rs (target/debug/deps/hir_ty-da16ccfda9040153)

running 1 test
test tests::regression::new_solver::regression_19957 ... FAILED

failures:

---- tests::regression::new_solver::regression_19957 stdout ----

thread 'tests::regression::new_solver::regression_19957' (150186) panicked at crates/hir-ty/src/tests.rs:246:9:
Unexpected type mismatches:
1109..1141: expected Pin<Box<dyn Future<Output = i32> + Send + 'async_trait>>, got Pin<Box<impl Future<Output = i32>>>

note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


failures:
    tests::regression::new_solver::regression_19957

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 920 filtered out; finished in 0.05s

error: test failed, to rerun pass `-p hir-ty --lib`

The results are consistent showing the original issue #19957 is not actually solved yet contrasting what said in #19957 (comment)

Additional test which I did on #19957 (comment) code snippet and got the similar result.

Copy link
Member

@ShoyuVanilla ShoyuVanilla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Thanks! I left a nit which fixes the CI failure

}

#[test]
// #[should_panic(expected = "Unexpected type mismatches")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be removed, I guess? 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the test will fail, this will still make the CI to fail.

Copy link
Member

@ShoyuVanilla ShoyuVanilla Nov 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I missed your comment above and I only looked into the tidy test failure. Yeah, this seems not fixed yet

Edit) Well, I've tested a bit more and this seems fixed. I guess we need to adjust some lang item imports and implementations in the test

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, adding the following impl to minicore fixes the failure 😄

impl<Ptr, U> CoerceUnsized<Pin<U>> for Pin<Ptr>
where
    Ptr: CoerceUnsized<U>,
{
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ShoyuVanilla ShoyuVanilla added this pull request to the merge queue Nov 21, 2025
Merged via the queue into rust-lang:master with commit b533f95 Nov 21, 2025
15 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants