diff --git a/src/libcore/unstable/intrinsics.rs b/src/libcore/unstable/intrinsics.rs index cfd305f4b70c1..a820c5d15a8db 100644 --- a/src/libcore/unstable/intrinsics.rs +++ b/src/libcore/unstable/intrinsics.rs @@ -42,12 +42,17 @@ pub extern "rust-intrinsic" { pub fn get_tydesc() -> *(); - pub fn init() -> T; + /// init is unsafe because it returns a zeroed-out datum, + /// which is unsafe unless T is POD. We don't have a POD + /// kind yet. (See #4074) + pub unsafe fn init() -> T; #[cfg(not(stage0))] pub unsafe fn uninit() -> T; - pub fn forget(_: T) -> (); + /// forget is unsafe because the caller is responsible for + /// ensuring the argument is deallocated already + pub unsafe fn forget(_: T) -> (); pub fn needs_drop() -> bool; diff --git a/src/test/compile-fail/forget-init-unsafe.rs b/src/test/compile-fail/forget-init-unsafe.rs new file mode 100644 index 0000000000000..2361b5ad6a9cf --- /dev/null +++ b/src/test/compile-fail/forget-init-unsafe.rs @@ -0,0 +1,17 @@ +// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use core::unstable::intrinsics::{init, forget}; + +// Test that the `forget` and `init` intrinsics are really unsafe +pub fn main() { + let stuff = init::(); //~ ERROR access to unsafe function requires unsafe + forget(stuff); //~ ERROR access to unsafe function requires unsafe +} \ No newline at end of file