syntax_ext: Improve and simplify code generated by #[global_allocator]
Instead of
```
mod allocator_abi { /* methods */ }
```
we now generate
```
const _: () = { /* methods */ }
```
and use `std_path` for paths referring to standard library entities.
This way we no longer need to generate `use` and `extern crate` imports, and `#[global_allocator]` starts working inside unnamed blocks.
This commit is contained in:
parent
76b1ffaf6c
commit
bf8fc8adfc
3 changed files with 34 additions and 61 deletions
|
|
@ -13,9 +13,10 @@ fn main() {
|
|||
#[global_allocator]
|
||||
pub static GLOBAL: A = A(AtomicUsize::new(0));
|
||||
|
||||
let n = GLOBAL.0.load(Ordering::SeqCst);
|
||||
let s = Box::new(0);
|
||||
helper::work_with(&s);
|
||||
assert_eq!(GLOBAL.0.load(Ordering::SeqCst), 1);
|
||||
assert_eq!(GLOBAL.0.load(Ordering::SeqCst), n + 1);
|
||||
drop(s);
|
||||
assert_eq!(GLOBAL.0.load(Ordering::SeqCst), 2);
|
||||
assert_eq!(GLOBAL.0.load(Ordering::SeqCst), n + 2);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,9 +17,10 @@ mod submodule {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
let n = submodule::GLOBAL.0.load(Ordering::SeqCst);
|
||||
let s = Box::new(0);
|
||||
helper::work_with(&s);
|
||||
assert_eq!(submodule::GLOBAL.0.load(Ordering::SeqCst), 1);
|
||||
assert_eq!(submodule::GLOBAL.0.load(Ordering::SeqCst), n + 1);
|
||||
drop(s);
|
||||
assert_eq!(submodule::GLOBAL.0.load(Ordering::SeqCst), 2);
|
||||
assert_eq!(submodule::GLOBAL.0.load(Ordering::SeqCst), n + 2);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue