Skip to content

Commit 0188093

Browse files
committed
Force vec! to expressions only
1 parent 557e4c1 commit 0188093

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

alloc/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@
140140
#![feature(type_alias_impl_trait)]
141141
#![feature(associated_type_bounds)]
142142
#![feature(slice_group_by)]
143+
#![feature(decl_macro)]
143144
// Allow testing this library
144145

145146
#[cfg(test)]
@@ -193,4 +194,11 @@ mod std {
193194
#[unstable(feature = "liballoc_internals", issue = "none", reason = "implementation detail")]
194195
pub mod __export {
195196
pub use core::format_args;
197+
198+
/// Force AST node to an expression to improve diagnostics in pattern position.
199+
#[rustc_macro_transparency = "semitransparent"]
200+
#[unstable(feature = "liballoc_internals", issue = "none", reason = "implementation detail")]
201+
pub macro force_expr($e:expr) {
202+
$e
203+
}
196204
}

alloc/src/macros.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@
3737
#[cfg(not(test))]
3838
#[macro_export]
3939
#[stable(feature = "rust1", since = "1.0.0")]
40-
#[allow_internal_unstable(box_syntax)]
40+
#[allow_internal_unstable(box_syntax, liballoc_internals)]
4141
macro_rules! vec {
4242
() => (
43-
$crate::vec::Vec::new()
43+
$crate::__export::force_expr!($crate::vec::Vec::new())
4444
);
4545
($elem:expr; $n:expr) => (
46-
$crate::vec::from_elem($elem, $n)
46+
$crate::__export::force_expr!($crate::vec::from_elem($elem, $n))
4747
);
4848
($($x:expr),+ $(,)?) => (
49-
<[_]>::into_vec(box [$($x),+])
49+
$crate::__export::force_expr!(<[_]>::into_vec(box [$($x),+]))
5050
);
5151
}
5252

0 commit comments

Comments
 (0)