Skip to content

Commit

Permalink
compiler: print the suggestion only for local macros
Browse files Browse the repository at this point in the history
And wrap the link in the diagnostic in angle brackets.

Signed-off-by: Lena Milizé <[email protected]>
  • Loading branch information
lovelymono committed Apr 12, 2023
1 parent 4b456cb commit 04f20d4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions compiler/rustc_expand/src/mbe/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,11 @@ pub(super) fn failed_to_match_macro<'cx>(
|| matches!(token.kind, TokenKind::Interpolated(_)))
{
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");
err.note("see <https://doc.rust-lang.org/nightly/reference/macros-by-example.html#forwarding-a-matched-fragment> for more information");

if !def_span.is_dummy() && !cx.source_map().is_imported(def_span) {
err.help("try using `:tt` instead in the macro definition");
}
}

// Check whether there's a missing comma in this macro call, like `println!("{}" a);`
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/macros/nonterminal-matching.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ LL | macro n(a $nt_item b) {
LL | complex_nonterminal!(enum E {});
| ------------------------------- in this macro invocation
= 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
= 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)

Expand Down

0 comments on commit 04f20d4

Please sign in to comment.