Skip to content

Commit e518e39

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

File tree

6 files changed

+13
-7
lines changed

6 files changed

+13
-7
lines changed

compiler/rustc_resolve/src/diagnostics.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1439,7 +1439,11 @@ 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 primary_span = ident.span;
1443+
let label_span = primary_span.with_hi(primary_span.hi() + BytePos(1)).shrink_to_hi();
1444+
let mut spans = MultiSpan::from_span(label_span);
1445+
spans.push_span_label(label_span, "put a macro name here");
1446+
err.subdiagnostic(MaybeMissingMacroRulesName { spans: spans });
14431447
return;
14441448
}
14451449

compiler/rustc_resolve/src/errors.rs

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 3 additions & 3 deletions
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:21
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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
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
45

56
fn main() {}

tests/ui/resolve/issue-118295.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ LL | macro_rules! {}
55
| ^^^^^^^^^^^
66
|
77
note: maybe you have forgotten to define a name for this `macro_rules!`
8-
--> $DIR/issue-118295.rs:1:1
8+
--> $DIR/issue-118295.rs:1:13
99
|
1010
LL | macro_rules! {}
11-
| ^^^^^^^^^^^
11+
| ^ put a macro name here
1212

1313
error: aborting due to 1 previous error
1414

0 commit comments

Comments
 (0)