This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +13
-5
lines changed Expand file tree Collapse file tree 4 files changed +13
-5
lines changed Original file line number Diff line number Diff line change 1
- 9c20b2a8cc7588decb6de25ac6a7912dcef24d65
1
+ e1b28cd2f16bd5b832183d7968cae3bb9213e78d
Original file line number Diff line number Diff line change @@ -51,8 +51,7 @@ impl Baz for i32 {
51
51
52
52
fn main ( ) {
53
53
let baz: & dyn Baz = & 1 ;
54
- // We already fail on the implicit upcast inserted here.
55
54
let baz_fake: & dyn Bar = unsafe { std:: mem:: transmute ( baz) } ;
56
- //~^ERROR: upcast on a pointer whose vtable does not match its type
57
55
let _err = baz_fake as & dyn Foo ;
56
+ //~^ERROR: upcast on a pointer whose vtable does not match its type
58
57
}
Original file line number Diff line number Diff line change 1
1
error: Undefined Behavior: upcast on a pointer whose vtable does not match its type
2
2
--> $DIR/dyn-upcast-trait-mismatch.rs:LL:CC
3
3
|
4
- LL | let baz_fake: &dyn Bar = unsafe { std::mem::transmute(baz) } ;
5
- | ^^^^^^^^^^^^^^^^ ^^^^^^^^ upcast on a pointer whose vtable does not match its type
4
+ LL | let _err = baz_fake as &dyn Foo ;
5
+ | ^^^^^^^^ upcast on a pointer whose vtable does not match its type
6
6
|
7
7
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
8
8
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
Original file line number Diff line number Diff line change @@ -6,6 +6,15 @@ fn main() {
6
6
diamond ( ) ;
7
7
struct_ ( ) ;
8
8
replace_vptr ( ) ;
9
+ vtable_mismatch_nop_cast ( ) ;
10
+ }
11
+
12
+ fn vtable_mismatch_nop_cast ( ) {
13
+ let ptr: & dyn std:: fmt:: Display = & 0 ;
14
+ // Even though the vtable is for the wrong trait, this cast doesn't actually change the needed
15
+ // vtable so it should still be allowed.
16
+ let ptr: * const ( dyn std:: fmt:: Debug + Send + Sync ) = unsafe { std:: mem:: transmute ( ptr) } ;
17
+ let _ptr2 = ptr as * const dyn std:: fmt:: Debug ;
9
18
}
10
19
11
20
fn basic ( ) {
You can’t perform that action at this time.
0 commit comments