Skip to content

Commit 04f20d4

Browse files
committed
compiler: print the suggestion only for local macros
And wrap the link in the diagnostic in angle brackets. Signed-off-by: Lena Milizé <[email protected]>
1 parent 4b456cb commit 04f20d4

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

compiler/rustc_expand/src/mbe/diagnostics.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,11 @@ pub(super) fn failed_to_match_macro<'cx>(
6767
|| matches!(token.kind, TokenKind::Interpolated(_)))
6868
{
6969
err.note("captured metavariables except for `:tt`, `:ident` and `:lifetime` cannot be compared to other tokens");
70-
err.note("see https://doc.rust-lang.org/nightly/reference/macros-by-example.html#forwarding-a-matched-fragment for more information");
71-
err.help("try using `:tt` instead in the macro definition");
70+
err.note("see <https://doc.rust-lang.org/nightly/reference/macros-by-example.html#forwarding-a-matched-fragment> for more information");
71+
72+
if !def_span.is_dummy() && !cx.source_map().is_imported(def_span) {
73+
err.help("try using `:tt` instead in the macro definition");
74+
}
7275
}
7376

7477
// Check whether there's a missing comma in this macro call, like `println!("{}" a);`

tests/ui/macros/nonterminal-matching.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ LL | macro n(a $nt_item b) {
1919
LL | complex_nonterminal!(enum E {});
2020
| ------------------------------- in this macro invocation
2121
= note: captured metavariables except for `:tt`, `:ident` and `:lifetime` cannot be compared to other tokens
22-
= note: see https://doc.rust-lang.org/nightly/reference/macros-by-example.html#forwarding-a-matched-fragment for more information
22+
= note: see <https://doc.rust-lang.org/nightly/reference/macros-by-example.html#forwarding-a-matched-fragment> for more information
2323
= help: try using `:tt` instead in the macro definition
2424
= note: this error originates in the macro `complex_nonterminal` (in Nightly builds, run with -Z macro-backtrace for more info)
2525

0 commit comments

Comments
 (0)