add a test for trait upcasting type mismatch

this adds a test asserting *incorrect* behavior that can be seen in
<https://github.com/rust-lang/rust-analyzer/issues/18083>, and a test
asserting the *correct* behavior for the case of no super traits.
This commit is contained in:
Waffle Lapkin 2025-01-16 00:27:44 +01:00
parent 7d337c7f35
commit 772266abeb
No known key found for this signature in database

View File

@ -1163,6 +1163,38 @@ struct Bar {
);
}
#[test]
fn trait_upcast_ok() {
check_diagnostics(
r#"
//- minicore: coerce_unsized
trait A: B {}
trait B {}
fn test(a: &dyn A) -> &dyn B {
a
//^ error: expected &dyn B, found &dyn A
}
"#,
);
}
#[test]
fn trait_upcast_err() {
check_diagnostics(
r#"
//- minicore: coerce_unsized
trait A {} // `A` does not have `B` as a supertrait, so no upcast :c
trait B {}
fn test(a: &dyn A) -> &dyn B {
a
//^ error: expected &dyn B, found &dyn A
}
"#,
);
}
#[test]
fn return_no_value() {
check_diagnostics_with_disabled(