organize compile-fail tests in folders
This commit is contained in:
parent
910afefcf6
commit
b2bf4ec2f5
73 changed files with 2 additions and 2 deletions
|
|
@ -0,0 +1,11 @@
|
|||
// Validation makes this fail in the wrong place
|
||||
// compile-flags: -Zmiri-disable-validation
|
||||
|
||||
fn main() {
|
||||
let b = Box::new(42);
|
||||
let g = unsafe {
|
||||
std::mem::transmute::<&Box<usize>, &fn(i32)>(&b)
|
||||
};
|
||||
|
||||
(*g)(42) //~ ERROR it does not point to a function
|
||||
}
|
||||
9
tests/compile-fail/function_pointers/cast_fn_ptr1.rs
Normal file
9
tests/compile-fail/function_pointers/cast_fn_ptr1.rs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
fn main() {
|
||||
fn f() {}
|
||||
|
||||
let g = unsafe {
|
||||
std::mem::transmute::<fn(), fn(i32)>(f)
|
||||
};
|
||||
|
||||
g(42) //~ ERROR calling a function with more arguments than it expected
|
||||
}
|
||||
9
tests/compile-fail/function_pointers/cast_fn_ptr2.rs
Normal file
9
tests/compile-fail/function_pointers/cast_fn_ptr2.rs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
fn main() {
|
||||
fn f(_ : (i32,i32)) {}
|
||||
|
||||
let g = unsafe {
|
||||
std::mem::transmute::<fn((i32,i32)), fn(i32)>(f)
|
||||
};
|
||||
|
||||
g(42) //~ ERROR calling a function with argument of type (i32, i32) passing data of type i32
|
||||
}
|
||||
10
tests/compile-fail/function_pointers/cast_fn_ptr3.rs
Normal file
10
tests/compile-fail/function_pointers/cast_fn_ptr3.rs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
fn main() {
|
||||
fn f(_ : (i32,i32)) {}
|
||||
|
||||
let g = unsafe {
|
||||
std::mem::transmute::<fn((i32,i32)), fn()>(f)
|
||||
};
|
||||
|
||||
g() //~ ERROR calling a function with fewer arguments than it requires
|
||||
}
|
||||
|
||||
9
tests/compile-fail/function_pointers/cast_fn_ptr4.rs
Normal file
9
tests/compile-fail/function_pointers/cast_fn_ptr4.rs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
fn main() {
|
||||
fn f(_ : *const [i32]) {}
|
||||
|
||||
let g = unsafe {
|
||||
std::mem::transmute::<fn(*const [i32]), fn(*const i32)>(f)
|
||||
};
|
||||
|
||||
g(&42 as *const i32) //~ ERROR calling a function with argument of type *const [i32] passing data of type *const i32
|
||||
}
|
||||
9
tests/compile-fail/function_pointers/cast_fn_ptr5.rs
Normal file
9
tests/compile-fail/function_pointers/cast_fn_ptr5.rs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
fn main() {
|
||||
fn f() -> u32 { 42 }
|
||||
|
||||
let g = unsafe {
|
||||
std::mem::transmute::<fn() -> u32, fn()>(f)
|
||||
};
|
||||
|
||||
g() //~ ERROR calling a function with return type u32 passing return place of type ()
|
||||
}
|
||||
10
tests/compile-fail/function_pointers/cast_int_to_fn_ptr.rs
Normal file
10
tests/compile-fail/function_pointers/cast_int_to_fn_ptr.rs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
// Validation makes this fail in the wrong place
|
||||
// compile-flags: -Zmiri-disable-validation
|
||||
|
||||
fn main() {
|
||||
let g = unsafe {
|
||||
std::mem::transmute::<usize, fn(i32)>(42)
|
||||
};
|
||||
|
||||
g(42) //~ ERROR invalid use of 42 as a pointer
|
||||
}
|
||||
8
tests/compile-fail/function_pointers/deref_fn_ptr.rs
Normal file
8
tests/compile-fail/function_pointers/deref_fn_ptr.rs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
fn f() {}
|
||||
|
||||
fn main() {
|
||||
let x: u8 = unsafe {
|
||||
*std::mem::transmute::<fn(), *const u8>(f) //~ ERROR contains a function
|
||||
};
|
||||
panic!("this should never print: {}", x);
|
||||
}
|
||||
12
tests/compile-fail/function_pointers/execute_memory.rs
Normal file
12
tests/compile-fail/function_pointers/execute_memory.rs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
// Validation makes this fail in the wrong place
|
||||
// compile-flags: -Zmiri-disable-validation
|
||||
|
||||
#![feature(box_syntax)]
|
||||
|
||||
fn main() {
|
||||
let x = box 42;
|
||||
unsafe {
|
||||
let f = std::mem::transmute::<Box<i32>, fn()>(x);
|
||||
f() //~ ERROR function pointer but it does not point to a function
|
||||
}
|
||||
}
|
||||
14
tests/compile-fail/function_pointers/fn_ptr_offset.rs
Normal file
14
tests/compile-fail/function_pointers/fn_ptr_offset.rs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
// Validation makes this fail in the wrong place
|
||||
// compile-flags: -Zmiri-disable-validation
|
||||
|
||||
use std::mem;
|
||||
|
||||
fn f() {}
|
||||
|
||||
fn main() {
|
||||
let x : fn() = f;
|
||||
let y : *mut u8 = unsafe { mem::transmute(x) };
|
||||
let y = y.wrapping_offset(1);
|
||||
let x : fn() = unsafe { mem::transmute(y) };
|
||||
x(); //~ ERROR function pointer but it does not point to a function
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue