Skip to content

Commit 70597f2

Browse files
authored
Rollup merge of #81241 - m-ou-se:force-expr-macro-rules, r=oli-obk
Turn alloc's force_expr macro into a regular macro_rules. This turns `alloc`'s `force_expr` macro into a regular `macro_rules`. Otherwise rust-analyzer doesn't understand `vec![]`. See rust-lang/rust-analyzer#7349 and #81080 (comment) Edit: See #81241 (comment) for a discussion of alternatives.
2 parents 3682a06 + 1934eaf commit 70597f2

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

library/alloc/src/lib.rs

-7
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,4 @@ pub mod vec;
189189
#[unstable(feature = "liballoc_internals", issue = "none", reason = "implementation detail")]
190190
pub mod __export {
191191
pub use core::format_args;
192-
193-
/// Force AST node to an expression to improve diagnostics in pattern position.
194-
#[rustc_macro_transparency = "semitransparent"]
195-
#[unstable(feature = "liballoc_internals", issue = "none", reason = "implementation detail")]
196-
pub macro force_expr($e:expr) {
197-
$e
198-
}
199192
}

library/alloc/src/macros.rs

+13-3
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@
4040
#[allow_internal_unstable(box_syntax, liballoc_internals)]
4141
macro_rules! vec {
4242
() => (
43-
$crate::__export::force_expr!($crate::vec::Vec::new())
43+
$crate::__rust_force_expr!($crate::vec::Vec::new())
4444
);
4545
($elem:expr; $n:expr) => (
46-
$crate::__export::force_expr!($crate::vec::from_elem($elem, $n))
46+
$crate::__rust_force_expr!($crate::vec::from_elem($elem, $n))
4747
);
4848
($($x:expr),+ $(,)?) => (
49-
$crate::__export::force_expr!(<[_]>::into_vec(box [$($x),+]))
49+
$crate::__rust_force_expr!(<[_]>::into_vec(box [$($x),+]))
5050
);
5151
}
5252

@@ -111,3 +111,13 @@ macro_rules! format {
111111
res
112112
}}
113113
}
114+
115+
/// Force AST node to an expression to improve diagnostics in pattern position.
116+
#[doc(hidden)]
117+
#[macro_export]
118+
#[unstable(feature = "liballoc_internals", issue = "none", reason = "implementation detail")]
119+
macro_rules! __rust_force_expr {
120+
($e:expr) => {
121+
$e
122+
};
123+
}

0 commit comments

Comments
 (0)