compiler: improve captured metavariables diagnostic
Adds a link to the relevant part of The Rust Reference in the eror message, and suggests a possible fix (replacing the fragment specifier with :tt in the macro definition). Fixes typos in the original message. Signed-off-by: Lena Milizé <me@lvmn.org>
This commit is contained in:
parent
87a2408b06
commit
4b456cb683
@ -66,7 +66,9 @@ pub(super) fn failed_to_match_macro<'cx>(
|
|||||||
&& (matches!(expected_token.kind, TokenKind::Interpolated(_))
|
&& (matches!(expected_token.kind, TokenKind::Interpolated(_))
|
||||||
|| matches!(token.kind, TokenKind::Interpolated(_)))
|
|| matches!(token.kind, TokenKind::Interpolated(_)))
|
||||||
{
|
{
|
||||||
err.note("captured metavariables except for `$tt`, `$ident` and `$lifetime` cannot be compared to other tokens");
|
err.note("captured metavariables except for `:tt`, `:ident` and `:lifetime` cannot be compared to other tokens");
|
||||||
|
err.note("see https://doc.rust-lang.org/nightly/reference/macros-by-example.html#forwarding-a-matched-fragment for more information");
|
||||||
|
err.help("try using `:tt` instead in the macro definition");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check whether there's a missing comma in this macro call, like `println!("{}" a);`
|
// Check whether there's a missing comma in this macro call, like `println!("{}" a);`
|
||||||
|
@ -18,7 +18,9 @@ LL | macro n(a $nt_item b) {
|
|||||||
...
|
...
|
||||||
LL | complex_nonterminal!(enum E {});
|
LL | complex_nonterminal!(enum E {});
|
||||||
| ------------------------------- in this macro invocation
|
| ------------------------------- in this macro invocation
|
||||||
= note: captured metavariables except for `$tt`, `$ident` and `$lifetime` cannot be compared to other tokens
|
= note: captured metavariables except for `:tt`, `:ident` and `:lifetime` cannot be compared to other tokens
|
||||||
|
= note: see https://doc.rust-lang.org/nightly/reference/macros-by-example.html#forwarding-a-matched-fragment for more information
|
||||||
|
= help: try using `:tt` instead in the macro definition
|
||||||
= note: this error originates in the macro `complex_nonterminal` (in Nightly builds, run with -Z macro-backtrace for more info)
|
= note: this error originates in the macro `complex_nonterminal` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
Loading…
x
Reference in New Issue
Block a user