From cf78ff3913f3efeefb2c90dcae18682f460b0d84 Mon Sep 17 00:00:00 2001 From: Volker Mische Date: Thu, 1 Feb 2018 00:21:43 +0100 Subject: [PATCH] Fix lang items box example code The `exchange_free` lang item is gone in favour of `box_free` [1]. Some warnings are also fixed by this commit. [1]: https://github.com/rust-lang/rust/commit/ca115dd083a1fe1d2b4892c5e50e49eb83ff1f3 --- .../src/language-features/lang-items.md | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/doc/unstable-book/src/language-features/lang-items.md b/src/doc/unstable-book/src/language-features/lang-items.md index 0137a052a62d8..c51674186146b 100644 --- a/src/doc/unstable-book/src/language-features/lang-items.md +++ b/src/doc/unstable-book/src/language-features/lang-items.md @@ -37,28 +37,23 @@ unsafe fn allocate(size: usize, _align: usize) -> *mut u8 { p } -#[lang = "exchange_free"] -unsafe fn deallocate(ptr: *mut u8, _size: usize, _align: usize) { - libc::free(ptr as *mut libc::c_void) -} - #[lang = "box_free"] unsafe fn box_free(ptr: *mut T) { - deallocate(ptr as *mut u8, ::core::mem::size_of_val(&*ptr), ::core::mem::align_of_val(&*ptr)); + libc::free(ptr as *mut libc::c_void) } #[start] -fn main(argc: isize, argv: *const *const u8) -> isize { - let x = box 1; +fn main(_argc: isize, _argv: *const *const u8) -> isize { + let _x = box 1; 0 } #[lang = "eh_personality"] extern fn rust_eh_personality() {} #[lang = "panic_fmt"] extern fn rust_begin_panic() -> ! { unsafe { intrinsics::abort() } } -# #[lang = "eh_unwind_resume"] extern fn rust_eh_unwind_resume() {} -# #[no_mangle] pub extern fn rust_eh_register_frames () {} -# #[no_mangle] pub extern fn rust_eh_unregister_frames () {} +#[lang = "eh_unwind_resume"] extern fn rust_eh_unwind_resume() {} +#[no_mangle] pub extern fn rust_eh_register_frames () {} +#[no_mangle] pub extern fn rust_eh_unregister_frames () {} ``` Note the use of `abort`: the `exchange_malloc` lang item is assumed to @@ -80,7 +75,7 @@ Other features provided by lang items include: Lang items are loaded lazily by the compiler; e.g. if one never uses `Box` then there is no need to define functions for `exchange_malloc` -and `exchange_free`. `rustc` will emit an error when an item is needed +and `box_free`. `rustc` will emit an error when an item is needed but not found in the current crate or any that it depends on. Most lang items are defined by `libcore`, but if you're trying to build @@ -318,4 +313,4 @@ the source code. - `phantom_data`: `libcore/marker.rs` - `freeze`: `libcore/marker.rs` - `debug_trait`: `libcore/fmt/mod.rs` - - `non_zero`: `libcore/nonzero.rs` \ No newline at end of file + - `non_zero`: `libcore/nonzero.rs`