Skip to content

Commit 2fca4ea

Browse files
committed
Add a label to point to the lacking macro name definition
1 parent 5be2ec7 commit 2fca4ea

File tree

6 files changed

+30
-8
lines changed

6 files changed

+30
-8
lines changed

compiler/rustc_resolve/src/diagnostics.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1439,7 +1439,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
14391439
);
14401440

14411441
if macro_kind == MacroKind::Bang && ident.name == sym::macro_rules {
1442-
err.subdiagnostic(MaybeMissingMacroRulesName { span: ident.span });
1442+
let label_span = ident.span.shrink_to_hi();
1443+
let mut spans = MultiSpan::from_span(label_span);
1444+
spans.push_span_label(label_span, "put a macro name here");
1445+
err.subdiagnostic(MaybeMissingMacroRulesName { spans: spans });
14431446
return;
14441447
}
14451448

compiler/rustc_resolve/src/errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ pub(crate) struct MacroSuggMovePosition {
667667
#[note(resolve_missing_macro_rules_name)]
668668
pub(crate) struct MaybeMissingMacroRulesName {
669669
#[primary_span]
670-
pub(crate) span: Span,
670+
pub(crate) spans: MultiSpan,
671671
}
672672

673673
#[derive(Subdiagnostic)]

tests/ui/macros/issue-118786.rs

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ macro_rules! make_macro {
77
macro_rules! $macro_name {
88
//~^ ERROR macro expansion ignores token `{` and any following
99
//~| ERROR cannot find macro `macro_rules` in this scope
10+
//~| put a macro name here
1011
() => {}
1112
}
1213
}

tests/ui/macros/issue-118786.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: macros that expand to items must be delimited with braces or followed by a semicolon
2-
--> $DIR/issue-118786.rs:15:13
2+
--> $DIR/issue-118786.rs:16:13
33
|
44
LL | make_macro!((meow));
55
| ^^^^^^
@@ -34,10 +34,10 @@ LL | make_macro!((meow));
3434
| ------------------- in this macro invocation
3535
|
3636
note: maybe you have forgotten to define a name for this `macro_rules!`
37-
--> $DIR/issue-118786.rs:7:9
37+
--> $DIR/issue-118786.rs:7:20
3838
|
3939
LL | macro_rules! $macro_name {
40-
| ^^^^^^^^^^^
40+
| ^ put a macro name here
4141
...
4242
LL | make_macro!((meow));
4343
| ------------------- in this macro invocation

tests/ui/resolve/issue-118295.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
macro_rules! {}
22
//~^ ERROR cannot find macro `macro_rules` in this scope
33
//~| NOTE maybe you have forgotten to define a name for this `macro_rules!`
4+
//~| put a macro name here
5+
6+
macro_rules!{}
7+
//~^ ERROR cannot find macro `macro_rules` in this scope
8+
//~| NOTE maybe you have forgotten to define a name for this `macro_rules!`
9+
//~| put a macro name here
410

511
fn main() {}

tests/ui/resolve/issue-118295.stderr

+15-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
11
error: cannot find macro `macro_rules` in this scope
2-
--> $DIR/issue-118295.rs:1:1
2+
--> $DIR/issue-118295.rs:6:1
33
|
4-
LL | macro_rules! {}
4+
LL | macro_rules!{}
55
| ^^^^^^^^^^^
66
|
77
note: maybe you have forgotten to define a name for this `macro_rules!`
8+
--> $DIR/issue-118295.rs:6:12
9+
|
10+
LL | macro_rules!{}
11+
| ^ put a macro name here
12+
13+
error: cannot find macro `macro_rules` in this scope
814
--> $DIR/issue-118295.rs:1:1
915
|
1016
LL | macro_rules! {}
1117
| ^^^^^^^^^^^
18+
|
19+
note: maybe you have forgotten to define a name for this `macro_rules!`
20+
--> $DIR/issue-118295.rs:1:12
21+
|
22+
LL | macro_rules! {}
23+
| ^ put a macro name here
1224

13-
error: aborting due to 1 previous error
25+
error: aborting due to 2 previous errors
1426

0 commit comments

Comments
 (0)