diff --git a/tests/compile-fail/maybe_null_pointer_deref_zst.rs b/tests/compile-fail/maybe_null_pointer_deref_zst.rs new file mode 100644 index 000000000000..d9f5ad4c696e --- /dev/null +++ b/tests/compile-fail/maybe_null_pointer_deref_zst.rs @@ -0,0 +1,5 @@ +fn main() { + // This pointer *could* be NULL so we cannot load from it, not even at ZST + let ptr = (&0u8 as *const u8).wrapping_sub(0x800) as *const (); + let _x: () = unsafe { *ptr }; //~ ERROR outside bounds +} diff --git a/tests/compile-fail/maybe_null_pointer_write_zst.rs b/tests/compile-fail/maybe_null_pointer_write_zst.rs new file mode 100644 index 000000000000..ef46a469c3ad --- /dev/null +++ b/tests/compile-fail/maybe_null_pointer_write_zst.rs @@ -0,0 +1,8 @@ +fn main() { + // This pointer *could* be NULL so we cannot load from it, not even at ZST. + // Not using the () type here, as writes of that type do not even have MIR generated. + // Also not assigning directly as that's array initialization, not assignment. + let zst_val = [1u8; 0]; + let ptr = (&0u8 as *const u8).wrapping_sub(0x800) as *mut [u8; 0]; + unsafe { *ptr = zst_val; } //~ ERROR outside bounds +} diff --git a/tests/compile-fail/null_pointer_deref_zst.rs b/tests/compile-fail/null_pointer_deref_zst.rs new file mode 100644 index 000000000000..a8b23368616e --- /dev/null +++ b/tests/compile-fail/null_pointer_deref_zst.rs @@ -0,0 +1,4 @@ +fn main() { + let x: () = unsafe { *std::ptr::null() }; //~ ERROR constant evaluation error: invalid use of NULL pointer + panic!("this should never print: {:?}", x); +} diff --git a/tests/compile-fail/null_pointer_write.rs b/tests/compile-fail/null_pointer_write.rs new file mode 100644 index 000000000000..affb040bdedf --- /dev/null +++ b/tests/compile-fail/null_pointer_write.rs @@ -0,0 +1,3 @@ +fn main() { + unsafe { *std::ptr::null_mut() = 0i32 }; //~ ERROR constant evaluation error: invalid use of NULL pointer +} diff --git a/tests/compile-fail/null_pointer_write_zst.rs b/tests/compile-fail/null_pointer_write_zst.rs new file mode 100644 index 000000000000..433c69dbb032 --- /dev/null +++ b/tests/compile-fail/null_pointer_write_zst.rs @@ -0,0 +1,6 @@ +fn main() { + // Not using the () type here, as writes of that type do not even have MIR generated. + // Also not assigning directly as that's array initialization, not assignment. + let zst_val = [1u8; 0]; + unsafe { *std::ptr::null_mut() = zst_val }; //~ ERROR constant evaluation error: invalid use of NULL pointer +} diff --git a/tests/run-pass/cast-rfc0401-vtable-kinds.rs b/tests/run-pass/cast-rfc0401-vtable-kinds.rs index afbd4760a3c9..ebae26996b7b 100644 --- a/tests/run-pass/cast-rfc0401-vtable-kinds.rs +++ b/tests/run-pass/cast-rfc0401-vtable-kinds.rs @@ -8,10 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - -// FIXME: remove the next line when https://github.com/rust-lang/rust/issues/43358 is resolved -// compile-flags: -Zmir-opt-level=0 - // Check that you can cast between different pointers to trait objects // whose vtable have the same kind (both lengths, or both trait pointers). diff --git a/tests/run-pass/const-vec-of-fns.rs b/tests/run-pass/const-vec-of-fns.rs index 0338a766e262..e100ad5f4692 100644 --- a/tests/run-pass/const-vec-of-fns.rs +++ b/tests/run-pass/const-vec-of-fns.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// pretty-expanded FIXME #23616 - /*! * Try to double-check that static fns have the right size (with or * without dummy env ptr, as appropriate) by iterating a size-2 array. diff --git a/tests/run-pass/issue-20575.rs b/tests/run-pass/issue-20575.rs index 7db7e3b28e8e..137d84c256be 100644 --- a/tests/run-pass/issue-20575.rs +++ b/tests/run-pass/issue-20575.rs @@ -10,8 +10,6 @@ // Test that overloaded calls work with zero arity closures -// pretty-expanded FIXME #23616 - fn main() { let functions: [Box Option<()>>; 1] = [Box::new(|| None)]; diff --git a/tests/run-pass/pointers.rs b/tests/run-pass/pointers.rs index 936ec73bcb8c..d8f030de0723 100644 --- a/tests/run-pass/pointers.rs +++ b/tests/run-pass/pointers.rs @@ -55,7 +55,11 @@ fn main() { assert_eq!(basic_ref_mut_var(), 3); assert_eq!(tuple_ref_mut(), (10, 22)); assert_eq!(match_ref_mut(), 42); - // FIXME: improve this test... how? + + // Compare even dangling pointers with NULL, and with others in the same allocation. assert!(dangling_pointer() != std::ptr::null()); assert!(match dangling_pointer() as usize { 0 => false, _ => true }); + let dangling = dangling_pointer(); + assert!(dangling == dangling); + assert!(dangling.wrapping_add(1) != dangling); } diff --git a/tests/run-pass/regions-lifetime-nonfree-late-bound.rs b/tests/run-pass/regions-lifetime-nonfree-late-bound.rs index 1aef95d8a3f3..96f1217a254e 100644 --- a/tests/run-pass/regions-lifetime-nonfree-late-bound.rs +++ b/tests/run-pass/regions-lifetime-nonfree-late-bound.rs @@ -22,8 +22,6 @@ // doing region-folding, when really all clients of the region-folding // case only want to see FREE lifetime variables, not bound ones. -// pretty-expanded FIXME #23616 - #![allow(unused_features)] #![feature(box_syntax)] diff --git a/tests/run-pass/sendable-class.rs b/tests/run-pass/sendable-class.rs index b3e07d00f010..66f0c84e23c1 100644 --- a/tests/run-pass/sendable-class.rs +++ b/tests/run-pass/sendable-class.rs @@ -10,8 +10,6 @@ // Test that a class with only sendable fields can be sent -// pretty-expanded FIXME #23616 - use std::sync::mpsc::channel; #[allow(dead_code)] diff --git a/tests/run-pass/zst.rs b/tests/run-pass/zst.rs index c1c88875c5c8..c3bae4062fc2 100644 --- a/tests/run-pass/zst.rs +++ b/tests/run-pass/zst.rs @@ -11,8 +11,23 @@ fn use_zst() -> A { } fn main() { + // Not using the () type here, as writes of that type do not even have MIR generated. + // Also not assigning directly as that's array initialization, not assignment. + let zst_val = [1u8; 0]; + assert_eq!(zst_ret(), A); assert_eq!(use_zst(), A); - let x = 42 as *mut (); - unsafe { *x = (); } + let x = 42 as *mut [u8; 0]; + // reading and writing is okay + unsafe { *x = zst_val; } + unsafe { let _y = *x; } + + // We should even be able to use "true" pointers for ZST when the allocation has been + // removed already. The box is for a non-ZST to make sure there actually is an allocation. + let mut x_box = Box::new(((), 1u8)); + let x = &mut x_box.0 as *mut _ as *mut [u8; 0]; + drop(x_box); + // reading and writing is okay + unsafe { *x = zst_val; } + unsafe { let _y = *x; } } diff --git a/tests/run-pass/zst2.rs b/tests/run-pass/zst2.rs deleted file mode 100644 index c2d7b88ea075..000000000000 --- a/tests/run-pass/zst2.rs +++ /dev/null @@ -1,12 +0,0 @@ -#![allow(dead_code)] - -#[derive(Debug)] -struct A; - -fn main() { - // can't use assert_eq, b/c that will try to print the pointer addresses with full MIR enabled - - // FIXME: Test disabled for now, see . - //assert!(&A as *const A as *const () == &() as *const _); - //assert!(&A as *const A == &A as *const A); -}