mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-01 06:51:58 +00:00
20976bae5c
Add #[rustc_box] and use it inside alloc This commit adds an alternative content boxing syntax, and uses it inside alloc. ```Rust #![feature(box_syntax)] fn foo() { let foo = box bar; } ``` is equivalent to ```Rust #![feature(rustc_attrs)] fn foo() { let foo = #[rustc_box] Box::new(bar); } ``` The usage inside the very performance relevant code in liballoc is the only remaining relevant usage of box syntax in the compiler (outside of tests, which are comparatively easy to port). box syntax was originally designed to be used by all Rust developers. This introduces a replacement syntax more tailored to only being used inside the Rust compiler, and with it, lays the groundwork for eventually removing box syntax. [Earlier work](https://github.com/rust-lang/rust/pull/87781#issuecomment-894714878) by `@nbdd0121` to lower `Box::new` to `box` during THIR -> MIR building ran into borrow checker problems, requiring the lowering to be adjusted in a way that led to [performance regressions](https://github.com/rust-lang/rust/pull/87781#issuecomment-894872367). The proposed change in this PR lowers `#[rustc_box] Box::new` -> `box` in the AST -> HIR lowering step, which is way earlier in the compiler, and thus should cause less issues both performance wise as well as regarding type inference/borrow checking/etc. Hopefully, future work can move the lowering further back in the compiler, as long as there are no performance regressions. |
||
---|---|---|
.. | ||
benches | ||
src | ||
tests | ||
Cargo.toml |