Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd3debc0

Browse files
authored
Rollup merge of#126929 - nnethercote:rm-__rust_force_expr, r=oli-obk
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#61933, which didn't even mention patterns.The motivation for this is#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.r? ```@oli-obk```
2 parentsb1f4397 +9828e96 commitd3debc0

File tree

3 files changed

+10
-17
lines changed

3 files changed

+10
-17
lines changed

‎library/alloc/src/macros.rs‎

Lines changed: 4 additions & 14 deletions
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-
}

‎tests/ui/macros/vec-macro-in-pattern.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
fnmain(){
66
matchSome(vec![42]){
7-
Some(vec![43]) =>{}//~ ERRORarbitrary expressions aren't allowed in patterns
7+
Some(vec![43]) =>{}//~ ERRORexpected pattern, found `#`
88
_ =>{}
99
}
1010
}

‎tests/ui/macros/vec-macro-in-pattern.stderr‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
error:arbitrary expressions aren't allowed in patterns
1+
error:expected pattern, found `#`
22
--> $DIR/vec-macro-in-pattern.rs:7:14
33
|
44
LL | Some(vec![43]) => {}
55
| ^^^^^^^^
6+
| |
7+
| expected pattern
8+
| in this macro invocation
9+
| this macro call doesn't expand to a pattern
610
|
7-
= note: the `expr` fragment specifier forces the metavariable's content to be an expression
811
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
912

1013
error: aborting due to 1 previous error

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp