Auto merge of #1985 - RalfJung:fn-ptr, r=RalfJung

update fn ptr tests

This adjusts the tests for https://github.com/rust-lang/rust/pull/94343.
This commit is contained in:
bors 2022-02-27 20:27:47 +00:00
commit e05a543f74
6 changed files with 19 additions and 15 deletions

View File

@ -1 +1 @@
3d127e2040b57157936f5f24e114a8b4c9a505ef
6a705566166debf5eff88c57140df607fa409aaa

View File

@ -266,7 +266,7 @@ fn report_msg<'tcx>(
) {
let span = stacktrace.first().map_or(DUMMY_SP, |fi| fi.span);
let mut err = match diag_level {
DiagLevel::Error => tcx.sess.struct_span_err(span, title),
DiagLevel::Error => tcx.sess.struct_span_err(span, title).forget_guarantee(),
DiagLevel::Warning => tcx.sess.struct_span_warn(span, title),
DiagLevel::Note => tcx.sess.diagnostic().span_note_diag(span, title),
};

View File

@ -1,10 +0,0 @@
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) }; //~ ERROR encountered a potentially null function pointer
}

View File

@ -1,5 +1,5 @@
#![allow(invalid_value)]
fn main() {
let _b: fn() = unsafe { std::mem::transmute(0usize) }; //~ ERROR encountered a potentially null function pointer
let _b: fn() = unsafe { std::mem::transmute(0usize) }; //~ ERROR encountered a null function pointer
}

View File

@ -62,9 +62,10 @@ fn main() {
// 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 _;
let mut b = Box::new(42u8);
let ptr = &mut *b as *mut u8;
drop(b);
let _x: fn() = mem::transmute(ptr);
let _x: fn() = mem::transmute(ptr.wrapping_offset(1));
}
}

View File

@ -0,0 +1,13 @@
#[repr(C)]
struct Demo(u64, bool, u64, u32, u64, u64, u64);
fn test() -> (Demo, Demo) {
let mut x = Demo(1, true, 3, 4, 5, 6, 7);
let mut y = Demo(10, false, 12, 13, 14, 15, 16);
std::mem::swap(&mut x, &mut y);
(x, y)
}
fn main() {
drop(test());
}