Skip to content

Commit

Permalink
Rollup merge of rust-lang#70632 - tspiteri:vec-new, r=sfackler
Browse files Browse the repository at this point in the history
expand vec![] to Vec::new()

The current expansion of `vec![]` calls `into_vec` on a boxed slice, which results in longer IR, and even after optimization, some unwinding artifacts are still present in the IR. This PR uses `Vec::new()` for `vec![]`.

This also allows `vec![]` to be used in const expressions.
  • Loading branch information
Dylan-DPC committed Mar 31, 2020
2 parents e87ccaf + 4d8273d commit 4b6231b
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/liballoc/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
#[stable(feature = "rust1", since = "1.0.0")]
#[allow_internal_unstable(box_syntax)]
macro_rules! vec {
() => (
$crate::vec::Vec::new()
);
($elem:expr; $n:expr) => (
$crate::vec::from_elem($elem, $n)
);
Expand All @@ -51,6 +54,9 @@ macro_rules! vec {
// NB see the slice::hack module in slice.rs for more information
#[cfg(test)]
macro_rules! vec {
() => (
$crate::vec::Vec::new()
);
($elem:expr; $n:expr) => (
$crate::vec::from_elem($elem, $n)
);
Expand Down

0 comments on commit 4b6231b

Please sign in to comment.