diff --git a/tests/compile-fail/environ-gets-deallocated.rs b/tests/compile-fail/environ-gets-deallocated.rs new file mode 100644 index 000000000000..014c8c431e7f --- /dev/null +++ b/tests/compile-fail/environ-gets-deallocated.rs @@ -0,0 +1,10 @@ +extern "C" { + static environ: *const *const u8; +} + +fn main() { + let pointer = unsafe { environ }; + let _x = unsafe { *pointer }; + std::env::set_var("FOO", "BAR"); + let _y = unsafe { *pointer }; //~ ERROR dangling pointer was dereferenced +}