Skip to content

Commit 10c3644

Browse files
committed
Update non-derive macro error message to match suggestion
It's now split between two errors, one to remove the invalid derive macro and one suggesting adding a new non-derive macro
1 parent 42f2be8 commit 10c3644

File tree

4 files changed

+27
-33
lines changed

4 files changed

+27
-33
lines changed

compiler/rustc_resolve/src/macros.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -549,15 +549,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
549549
err.span_label(path.span, format!("not {} {}", article, expected));
550550

551551
if kind == MacroKind::Derive && ext.macro_kind() != MacroKind::Derive {
552-
// Suggest removing the derive() as the macro isn't Derive
553-
let opening_span =
554-
path.span.shrink_to_lo().with_lo(path.span.lo() - rustc_span::BytePos(7));
555-
let closing_span =
556-
path.span.shrink_to_hi().with_hi(path.span.hi() + rustc_span::BytePos(1));
557-
err.span_help(
558-
vec![opening_span, closing_span],
559-
"remove the surrounding \"derive()\":",
560-
);
552+
// Suggest moving the macro our of the derive() as the macro isn't Derive
553+
err.span_help(path.span, "Remove from the surrounding `derive()`");
554+
err.help(format!("Add as non-Derive macro\n`#[{}]`", path_str));
561555
}
562556

563557
err.emit();

tests/ui/macros/macro-path-prelude-fail-4.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ error: expected derive macro, found built-in attribute `inline`
22
--> $DIR/macro-path-prelude-fail-4.rs:1:10
33
|
44
LL | #[derive(inline)]
5-
| ^^^^^^ not a derive macro
5+
| ^^^^^^
6+
| |
7+
| not a derive macro
8+
| help: Remove from the surrounding `derive()`
69
|
7-
help: remove the surrounding "derive()":
8-
--> $DIR/macro-path-prelude-fail-4.rs:1:3
9-
|
10-
LL | #[derive(inline)]
11-
| ^^^^^^^ ^
10+
= help: Add as non-Derive macro
11+
`#[inline]`
1212

1313
error: aborting due to previous error
1414

tests/ui/proc-macro/macro-namespace-reserved-2.stderr

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ error: expected derive macro, found attribute macro `my_macro_attr`
5656
--> $DIR/macro-namespace-reserved-2.rs:53:10
5757
|
5858
LL | #[derive(my_macro_attr)]
59-
| ^^^^^^^^^^^^^ not a derive macro
60-
|
61-
help: remove the surrounding "derive()":
62-
--> $DIR/macro-namespace-reserved-2.rs:53:3
59+
| ^^^^^^^^^^^^^
60+
| |
61+
| not a derive macro
62+
| help: Remove from the surrounding `derive()`
6363
|
64-
LL | #[derive(my_macro_attr)]
65-
| ^^^^^^^ ^
64+
= help: Add as non-Derive macro
65+
`#[my_macro_attr]`
6666

6767
error: can't use a procedural macro from the same crate that defines it
6868
--> $DIR/macro-namespace-reserved-2.rs:56:10
@@ -92,13 +92,13 @@ error: expected derive macro, found macro `crate::my_macro`
9292
--> $DIR/macro-namespace-reserved-2.rs:50:10
9393
|
9494
LL | #[derive(crate::my_macro)]
95-
| ^^^^^^^^^^^^^^^ not a derive macro
96-
|
97-
help: remove the surrounding "derive()":
98-
--> $DIR/macro-namespace-reserved-2.rs:50:3
95+
| ^^^^^^^^^^^^^^^
96+
| |
97+
| not a derive macro
98+
| help: Remove from the surrounding `derive()`
9999
|
100-
LL | #[derive(crate::my_macro)]
101-
| ^^^^^^^ ^
100+
= help: Add as non-Derive macro
101+
`#[crate::my_macro]`
102102

103103
error: cannot find macro `my_macro_attr` in this scope
104104
--> $DIR/macro-namespace-reserved-2.rs:28:5

tests/ui/tool-attributes/tool-attributes-misplaced-2.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ error: expected derive macro, found tool attribute `rustfmt::skip`
22
--> $DIR/tool-attributes-misplaced-2.rs:1:10
33
|
44
LL | #[derive(rustfmt::skip)]
5-
| ^^^^^^^^^^^^^ not a derive macro
5+
| ^^^^^^^^^^^^^
6+
| |
7+
| not a derive macro
8+
| help: Remove from the surrounding `derive()`
69
|
7-
help: remove the surrounding "derive()":
8-
--> $DIR/tool-attributes-misplaced-2.rs:1:3
9-
|
10-
LL | #[derive(rustfmt::skip)]
11-
| ^^^^^^^ ^
10+
= help: Add as non-Derive macro
11+
`#[rustfmt::skip]`
1212

1313
error: expected macro, found tool attribute `rustfmt::skip`
1414
--> $DIR/tool-attributes-misplaced-2.rs:5:5

0 commit comments

Comments
 (0)