rm box_items
fix in plugin.md fmt
This commit is contained in:
parent
94524020ea
commit
f1ded91a48
2 changed files with 14 additions and 6 deletions
|
@ -16,18 +16,26 @@ and one for deallocation. A freestanding program that uses the `Box`
|
|||
sugar for dynamic allocations via `malloc` and `free`:
|
||||
|
||||
```rust,ignore (libc-is-finicky)
|
||||
#![feature(lang_items, box_syntax, start, libc, core_intrinsics, rustc_private)]
|
||||
#![feature(lang_items, start, libc, core_intrinsics, rustc_private, rustc_attrs)]
|
||||
#![no_std]
|
||||
use core::intrinsics;
|
||||
use core::panic::PanicInfo;
|
||||
use core::ptr::NonNull;
|
||||
|
||||
extern crate libc;
|
||||
|
||||
struct Unique<T>(*mut T);
|
||||
struct Unique<T>(NonNull<T>);
|
||||
|
||||
#[lang = "owned_box"]
|
||||
pub struct Box<T>(Unique<T>);
|
||||
|
||||
impl<T> Box<T> {
|
||||
pub fn new(x: T) -> Self {
|
||||
#[rustc_box]
|
||||
Box::new(x)
|
||||
}
|
||||
}
|
||||
|
||||
#[lang = "exchange_malloc"]
|
||||
unsafe fn allocate(size: usize, _align: usize) -> *mut u8 {
|
||||
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) {
|
|||
|
||||
#[start]
|
||||
fn main(_argc: isize, _argv: *const *const u8) -> isize {
|
||||
let _x = box 1;
|
||||
let _x = Box::new(1);
|
||||
|
||||
0
|
||||
}
|
||||
|
||||
#[lang = "eh_personality"] extern fn rust_eh_personality() {}
|
||||
#[lang = "panic_impl"] extern fn rust_begin_panic(info: &PanicInfo) -> ! { unsafe { intrinsics::abort() } }
|
||||
#[lang = "panic_impl"] extern fn rust_begin_panic(_info: &PanicInfo) -> ! { intrinsics::abort() }
|
||||
#[no_mangle] pub extern fn rust_eh_register_frames () {}
|
||||
#[no_mangle] pub extern fn rust_eh_unregister_frames () {}
|
||||
```
|
||||
|
|
|
@ -37,7 +37,7 @@ additional checks for code style, safety, etc. Now let's write a plugin
|
|||
that warns about any item named `lintme`.
|
||||
|
||||
```rust,ignore (requires-stage-2)
|
||||
#![feature(box_syntax, rustc_private)]
|
||||
#![feature(rustc_private)]
|
||||
|
||||
extern crate rustc_ast;
|
||||
|
||||
|
@ -68,7 +68,7 @@ impl EarlyLintPass for Pass {
|
|||
#[no_mangle]
|
||||
fn __rustc_plugin_registrar(reg: &mut Registry) {
|
||||
reg.lint_store.register_lints(&[&TEST_LINT]);
|
||||
reg.lint_store.register_early_pass(|| box Pass);
|
||||
reg.lint_store.register_early_pass(|| Box::new(Pass));
|
||||
}
|
||||
```
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue