Skip to content

Commit 028026b

Browse files
committed
Remove __rust_force_expr.
This was added (with a different name) to improve an error message. It is no longer needed -- removing it changes the error message, but overall I think the new message is no worse: - the mention of `#` in the first line is a little worse, - but the extra context makes it very clear what the problem is, perhaps even clearer than the old message, - and the removal of the note about the `expr` fragment (an internal detail of `__rust_force_expr`) is an improvement. Overall I think the error is quite clear and still far better than the old message that prompted rust-lang#61933, which didn't even mention patterns. The motivation for this is rust-lang#124141, which will cause pasted metavariables to be tokenized and reparsed instead of the AST node being cached. This change in behaviour occasionally has a non-zero perf cost, and `__rust_force_expr` causes the tokenize/reparse step to occur twice. Removing `__rust_force_expr` greatly reduces the extra overhead for the `deep-vector` benchmark.
1 parent 9a945fd commit 028026b

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

alloc/src/macros.rs

+4-14
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,18 @@
4141
#[allow_internal_unstable(rustc_attrs, liballoc_internals)]
4242
macro_rules! vec {
4343
() => (
44-
$crate::__rust_force_expr!($crate::vec::Vec::new())
44+
$crate::vec::Vec::new()
4545
);
4646
($elem:expr; $n:expr) => (
47-
$crate::__rust_force_expr!($crate::vec::from_elem($elem, $n))
47+
$crate::vec::from_elem($elem, $n)
4848
);
4949
($($x:expr),+ $(,)?) => (
50-
$crate::__rust_force_expr!(<[_]>::into_vec(
50+
<[_]>::into_vec(
5151
// This rustc_box is not required, but it produces a dramatic improvement in compile
5252
// time when constructing arrays with many elements.
5353
#[rustc_box]
5454
$crate::boxed::Box::new([$($x),+])
55-
))
55+
)
5656
);
5757
}
5858

@@ -126,13 +126,3 @@ macro_rules! format {
126126
res
127127
}}
128128
}
129-
130-
/// Force AST node to an expression to improve diagnostics in pattern position.
131-
#[doc(hidden)]
132-
#[macro_export]
133-
#[unstable(feature = "liballoc_internals", issue = "none", reason = "implementation detail")]
134-
macro_rules! __rust_force_expr {
135-
($e:expr) => {
136-
$e
137-
};
138-
}

0 commit comments

Comments
 (0)