Add a test for *const Tr<A> to *const Tr<B> casts

This commit is contained in:
Maybe Waffle 2024-01-22 17:21:57 +00:00 committed by Maybe Lapkin
parent e2cf31a614
commit 36b1f4411d
2 changed files with 41 additions and 0 deletions

View File

@ -0,0 +1,30 @@
// check-fail
//
// issue: <https://github.com/rust-lang/rust/issues/120222>
trait A {}
impl<T> A for T {}
trait B {}
impl<T> B for T {}
trait Trait<G> {}
struct X;
impl<T> Trait<X> for T {}
struct Y;
impl<T> Trait<Y> for T {}
fn main() {
let a: *const dyn A = &();
let b: *const dyn B = a as _; //~ error: casting `*const dyn A` as `*const dyn B` is invalid
let x: *const dyn Trait<X> = &();
let y: *const dyn Trait<Y> = x as _;
_ = (b, y);
}
fn generic<T>(x: *const dyn Trait<X>, t: *const dyn Trait<T>) {
let _: *const dyn Trait<T> = x as _;
let _: *const dyn Trait<X> = t as _;
}

View File

@ -0,0 +1,11 @@
error[E0606]: casting `*const dyn A` as `*const dyn B` is invalid
--> $DIR/ptr-to-trait-obj-different-args.rs:19:27
|
LL | let b: *const dyn B = a as _;
| ^^^^^^
|
= note: vtable kinds may not match
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0606`.