Add a test for *const Tr<A>
to *const Tr<B>
casts
This commit is contained in:
parent
e2cf31a614
commit
36b1f4411d
30
tests/ui/cast/ptr-to-trait-obj-different-args.rs
Normal file
30
tests/ui/cast/ptr-to-trait-obj-different-args.rs
Normal 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 _;
|
||||
}
|
11
tests/ui/cast/ptr-to-trait-obj-different-args.stderr
Normal file
11
tests/ui/cast/ptr-to-trait-obj-different-args.stderr
Normal 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`.
|
Loading…
Reference in New Issue
Block a user