mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 11:20:54 +00:00
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:
parent
7d337c7f35
commit
772266abeb
@ -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(
|
||||
|
Loading…
x
Reference in New Issue
Block a user