Skip to content

Commit cf78ff3

Browse files
authored
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]: ca115dd
1 parent 560a2f4 commit cf78ff3

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

src/doc/unstable-book/src/language-features/lang-items.md

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,28 +37,23 @@ unsafe fn allocate(size: usize, _align: usize) -> *mut u8 {
3737
p
3838
}
3939
40-
#[lang = "exchange_free"]
41-
unsafe fn deallocate(ptr: *mut u8, _size: usize, _align: usize) {
42-
libc::free(ptr as *mut libc::c_void)
43-
}
44-
4540
#[lang = "box_free"]
4641
unsafe fn box_free<T: ?Sized>(ptr: *mut T) {
47-
deallocate(ptr as *mut u8, ::core::mem::size_of_val(&*ptr), ::core::mem::align_of_val(&*ptr));
42+
libc::free(ptr as *mut libc::c_void)
4843
}
4944
5045
#[start]
51-
fn main(argc: isize, argv: *const *const u8) -> isize {
52-
let x = box 1;
46+
fn main(_argc: isize, _argv: *const *const u8) -> isize {
47+
let _x = box 1;
5348
5449
0
5550
}
5651
5752
#[lang = "eh_personality"] extern fn rust_eh_personality() {}
5853
#[lang = "panic_fmt"] extern fn rust_begin_panic() -> ! { unsafe { intrinsics::abort() } }
59-
# #[lang = "eh_unwind_resume"] extern fn rust_eh_unwind_resume() {}
60-
# #[no_mangle] pub extern fn rust_eh_register_frames () {}
61-
# #[no_mangle] pub extern fn rust_eh_unregister_frames () {}
54+
#[lang = "eh_unwind_resume"] extern fn rust_eh_unwind_resume() {}
55+
#[no_mangle] pub extern fn rust_eh_register_frames () {}
56+
#[no_mangle] pub extern fn rust_eh_unregister_frames () {}
6257
```
6358

6459
Note the use of `abort`: the `exchange_malloc` lang item is assumed to
@@ -80,7 +75,7 @@ Other features provided by lang items include:
8075

8176
Lang items are loaded lazily by the compiler; e.g. if one never uses
8277
`Box` then there is no need to define functions for `exchange_malloc`
83-
and `exchange_free`. `rustc` will emit an error when an item is needed
78+
and `box_free`. `rustc` will emit an error when an item is needed
8479
but not found in the current crate or any that it depends on.
8580

8681
Most lang items are defined by `libcore`, but if you're trying to build
@@ -318,4 +313,4 @@ the source code.
318313
- `phantom_data`: `libcore/marker.rs`
319314
- `freeze`: `libcore/marker.rs`
320315
- `debug_trait`: `libcore/fmt/mod.rs`
321-
- `non_zero`: `libcore/nonzero.rs`
316+
- `non_zero`: `libcore/nonzero.rs`

0 commit comments

Comments
 (0)