test for Stacked Borrows error during vtable validation
This commit is contained in:
parent
ada7b72a87
commit
069d8fdb71
19
tests/fail/stacked_borrows/vtable.rs
Normal file
19
tests/fail/stacked_borrows/vtable.rs
Normal file
@ -0,0 +1,19 @@
|
||||
// error-pattern: vtable pointer does not have permission
|
||||
#![feature(ptr_metadata)]
|
||||
|
||||
trait Foo {}
|
||||
|
||||
impl Foo for u32 {}
|
||||
|
||||
fn uwu(thin: *const (), meta: &'static ()) -> *const dyn Foo {
|
||||
core::ptr::from_raw_parts(thin, unsafe { core::mem::transmute(meta) })
|
||||
}
|
||||
|
||||
fn main() {
|
||||
unsafe {
|
||||
let orig = 1_u32;
|
||||
let x = &orig as &dyn Foo;
|
||||
let (ptr, meta) = (x as *const dyn Foo).to_raw_parts();
|
||||
let _ = uwu(ptr, core::mem::transmute(meta));
|
||||
}
|
||||
}
|
25
tests/fail/stacked_borrows/vtable.stderr
Normal file
25
tests/fail/stacked_borrows/vtable.stderr
Normal file
@ -0,0 +1,25 @@
|
||||
error: Undefined Behavior: type validation failed: encountered vtable pointer does not have permission to read drop function pointer
|
||||
--> RUSTLIB/core/src/ptr/metadata.rs:LL:CC
|
||||
|
|
||||
LL | unsafe { PtrRepr { components: PtrComponents { data_address, metadata } }.const_ptr }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered vtable pointer does not have permission to read drop function pointer
|
||||
|
|
||||
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
|
||||
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
|
||||
|
||||
= note: inside `std::ptr::from_raw_parts::<dyn Foo>` at RUSTLIB/core/src/ptr/metadata.rs:LL:CC
|
||||
note: inside `uwu` at $DIR/vtable.rs:LL:CC
|
||||
--> $DIR/vtable.rs:LL:CC
|
||||
|
|
||||
LL | core::ptr::from_raw_parts(thin, unsafe { core::mem::transmute(meta) })
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
note: inside `main` at $DIR/vtable.rs:LL:CC
|
||||
--> $DIR/vtable.rs:LL:CC
|
||||
|
|
||||
LL | let _ = uwu(ptr, core::mem::transmute(meta));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
|
||||
|
||||
error: aborting due to previous error
|
||||
|
Loading…
x
Reference in New Issue
Block a user