rustup
This commit is contained in:
parent
6a39eeb764
commit
444396d620
6 changed files with 19 additions and 11 deletions
|
|
@ -1 +1 @@
|
|||
b8967b0d52a2ba5f0c9da0da03e78ccba5534e4a
|
||||
3d127e2040b57157936f5f24e114a8b4c9a505ef
|
||||
|
|
|
|||
|
|
@ -1,8 +0,0 @@
|
|||
#![feature(box_syntax)]
|
||||
|
||||
fn main() {
|
||||
let x = box 42;
|
||||
unsafe {
|
||||
let _f = std::mem::transmute::<Box<i32>, fn()>(x); //~ ERROR expected a function pointer
|
||||
}
|
||||
}
|
||||
|
|
@ -6,5 +6,5 @@ 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) }; //~ ERROR expected a function pointer
|
||||
let _x : fn() = unsafe { mem::transmute(y) }; //~ ERROR encountered a potentially null function pointer
|
||||
}
|
||||
|
|
|
|||
5
tests/compile-fail/validity/invalid_fnptr_null.rs
Normal file
5
tests/compile-fail/validity/invalid_fnptr_null.rs
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
#![allow(invalid_value)]
|
||||
|
||||
fn main() {
|
||||
let _b: fn() = unsafe { std::mem::transmute(0usize) }; //~ ERROR encountered a potentially null function pointer
|
||||
}
|
||||
|
|
@ -6,5 +6,5 @@ union MyUninit {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
let _b = unsafe { MyUninit { init: () }.uninit }; //~ ERROR encountered uninitialized bytes, but expected a function pointer
|
||||
let _b = unsafe { MyUninit { init: () }.uninit }; //~ ERROR encountered uninitialized bytes
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
use std::mem;
|
||||
|
||||
trait Answer {
|
||||
fn answer() -> Self;
|
||||
}
|
||||
|
|
@ -56,4 +58,13 @@ fn main() {
|
|||
assert!(return_fn_ptr(g) == g);
|
||||
assert!(return_fn_ptr(g) as unsafe fn() -> i32 == g as fn() -> i32 as unsafe fn() -> i32);
|
||||
assert!(return_fn_ptr(f) != f);
|
||||
|
||||
// Any non-null value is okay for function pointers.
|
||||
unsafe {
|
||||
let _x: fn() = mem::transmute(1usize);
|
||||
let mut b = Box::new(42);
|
||||
let ptr = &mut *b as *mut _;
|
||||
drop(b);
|
||||
let _x: fn() = mem::transmute(ptr);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue