Auto merge of #1984 - RalfJung:rustup, r=RalfJung

rustup
This commit is contained in:
bors 2022-02-24 15:57:56 +00:00
commit 538aedf099
6 changed files with 19 additions and 11 deletions

View file

@ -1 +1 @@
b8967b0d52a2ba5f0c9da0da03e78ccba5534e4a
3d127e2040b57157936f5f24e114a8b4c9a505ef

View file

@ -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
}
}

View file

@ -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
}

View 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
}

View file

@ -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
}

View file

@ -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);
}
}