Skip to content

Commit

Permalink
add a test for trait upcasting type mismatch
Browse files Browse the repository at this point in the history
this adds a test asserting *incorrect* behavior that can be seen in
<rust-lang#18083>, and a test
asserting the *correct* behavior for the case of no super traits.
  • Loading branch information
WaffleLapkin committed Jan 15, 2025
1 parent 7d337c7 commit 772266a
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions crates/ide-diagnostics/src/handlers/type_mismatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 772266a

Please sign in to comment.