Skip to content

Commit f1ded91

Browse files
author
Gimbles
committed
rm box_items
fix in plugin.md fmt
1 parent 9452402 commit f1ded91

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

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

+12-4
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,26 @@ and one for deallocation. A freestanding program that uses the `Box`
1616
sugar for dynamic allocations via `malloc` and `free`:
1717

1818
```rust,ignore (libc-is-finicky)
19-
#![feature(lang_items, box_syntax, start, libc, core_intrinsics, rustc_private)]
19+
#![feature(lang_items, start, libc, core_intrinsics, rustc_private, rustc_attrs)]
2020
#![no_std]
2121
use core::intrinsics;
2222
use core::panic::PanicInfo;
23+
use core::ptr::NonNull;
2324
2425
extern crate libc;
2526
26-
struct Unique<T>(*mut T);
27+
struct Unique<T>(NonNull<T>);
2728
2829
#[lang = "owned_box"]
2930
pub struct Box<T>(Unique<T>);
3031
32+
impl<T> Box<T> {
33+
pub fn new(x: T) -> Self {
34+
#[rustc_box]
35+
Box::new(x)
36+
}
37+
}
38+
3139
#[lang = "exchange_malloc"]
3240
unsafe fn allocate(size: usize, _align: usize) -> *mut u8 {
3341
let p = libc::malloc(size as libc::size_t) as *mut u8;
@@ -47,13 +55,13 @@ unsafe fn box_free<T: ?Sized>(ptr: *mut T) {
4755
4856
#[start]
4957
fn main(_argc: isize, _argv: *const *const u8) -> isize {
50-
let _x = box 1;
58+
let _x = Box::new(1);
5159
5260
0
5361
}
5462
5563
#[lang = "eh_personality"] extern fn rust_eh_personality() {}
56-
#[lang = "panic_impl"] extern fn rust_begin_panic(info: &PanicInfo) -> ! { unsafe { intrinsics::abort() } }
64+
#[lang = "panic_impl"] extern fn rust_begin_panic(_info: &PanicInfo) -> ! { intrinsics::abort() }
5765
#[no_mangle] pub extern fn rust_eh_register_frames () {}
5866
#[no_mangle] pub extern fn rust_eh_unregister_frames () {}
5967
```

src/doc/unstable-book/src/language-features/plugin.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ additional checks for code style, safety, etc. Now let's write a plugin
3737
that warns about any item named `lintme`.
3838

3939
```rust,ignore (requires-stage-2)
40-
#![feature(box_syntax, rustc_private)]
40+
#![feature(rustc_private)]
4141
4242
extern crate rustc_ast;
4343
@@ -68,7 +68,7 @@ impl EarlyLintPass for Pass {
6868
#[no_mangle]
6969
fn __rustc_plugin_registrar(reg: &mut Registry) {
7070
reg.lint_store.register_lints(&[&TEST_LINT]);
71-
reg.lint_store.register_early_pass(|| box Pass);
71+
reg.lint_store.register_early_pass(|| Box::new(Pass));
7272
}
7373
```
7474

0 commit comments

Comments
 (0)