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:
Vadim Petrochenkov 2019-07-19 02:51:07 +03:00
parent 76b1ffaf6c
commit bf8fc8adfc
3 changed files with 34 additions and 61 deletions

View file

@ -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);
}

View file

@ -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);
}