Skip to content

Commit 46bb94f

Browse files
committed
feat: add regression test for #19957
1 parent a91049e commit 46bb94f

File tree

1 file changed

+50
-0
lines changed
  • src/tools/rust-analyzer/crates/hir-ty/src/tests/regression

1 file changed

+50
-0
lines changed

src/tools/rust-analyzer/crates/hir-ty/src/tests/regression/new_solver.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,3 +552,53 @@ where
552552
"#]],
553553
);
554554
}
555+
556+
#[test]
557+
fn regression_19957() {
558+
// async-trait patterns should not produce false type mismatches between
559+
// Pin<Box<dyn Future>> and Pin<Box<impl Future>>
560+
check_no_mismatches(
561+
r#"
562+
//- minicore: future, pin, result, error, send
563+
use core::{future::Future, pin::Pin};
564+
565+
pub enum SimpleAsyncTraitResult {
566+
Ok,
567+
Error,
568+
}
569+
570+
pub struct ExampleData {
571+
pub id: i32,
572+
pub name: String,
573+
}
574+
// As we can't directly use #[async_trait] directly in tests
575+
// This simulates what #[async_trait] expands to
576+
pub trait SimpleAsyncTraitModel {
577+
fn save<'life0, 'async_trait>(
578+
&'life0 self,
579+
) -> Pin<Box<dyn Future<Output = Result<SimpleAsyncTraitResult, Box<dyn core::error::Error + Send + Sync>>> + Send + 'async_trait>>
580+
where
581+
'life0: 'async_trait,
582+
Self: 'async_trait;
583+
}
584+
585+
impl SimpleAsyncTraitModel for ExampleData {
586+
fn save<'life0, 'async_trait>(
587+
&'life0 self,
588+
) -> Pin<Box<dyn Future<Output = Result<SimpleAsyncTraitResult, Box<dyn core::error::Error + Send + Sync>>> + Send + 'async_trait>>
589+
where
590+
'life0: 'async_trait,
591+
Self: 'async_trait,
592+
{
593+
Box::pin(async move {
594+
if self.id > 0 {
595+
Ok(SimpleAsyncTraitResult::Ok)
596+
} else {
597+
Ok(SimpleAsyncTraitResult::Error)
598+
}
599+
})
600+
}
601+
}
602+
"#,
603+
);
604+
}

0 commit comments

Comments
 (0)