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
This commit is contained in:
Tom Martin 2023-03-30 21:43:32 +01:00
parent 42f2be8a8c
commit 10c36445ff
No known key found for this signature in database
GPG Key ID: 73A733F9629F5AC5
4 changed files with 27 additions and 33 deletions

View File

@ -549,15 +549,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
err.span_label(path.span, format!("not {} {}", article, expected));
if kind == MacroKind::Derive && ext.macro_kind() != MacroKind::Derive {
// Suggest removing the derive() as the macro isn't Derive
let opening_span =
path.span.shrink_to_lo().with_lo(path.span.lo() - rustc_span::BytePos(7));
let closing_span =
path.span.shrink_to_hi().with_hi(path.span.hi() + rustc_span::BytePos(1));
err.span_help(
vec![opening_span, closing_span],
"remove the surrounding \"derive()\":",
);
// Suggest moving the macro our of the derive() as the macro isn't Derive
err.span_help(path.span, "Remove from the surrounding `derive()`");
err.help(format!("Add as non-Derive macro\n`#[{}]`", path_str));
}
err.emit();

View File

@ -2,13 +2,13 @@ error: expected derive macro, found built-in attribute `inline`
--> $DIR/macro-path-prelude-fail-4.rs:1:10
|
LL | #[derive(inline)]
| ^^^^^^ not a derive macro
| ^^^^^^
| |
| not a derive macro
| help: Remove from the surrounding `derive()`
|
help: remove the surrounding "derive()":
--> $DIR/macro-path-prelude-fail-4.rs:1:3
|
LL | #[derive(inline)]
| ^^^^^^^ ^
= help: Add as non-Derive macro
`#[inline]`
error: aborting due to previous error

View File

@ -56,13 +56,13 @@ error: expected derive macro, found attribute macro `my_macro_attr`
--> $DIR/macro-namespace-reserved-2.rs:53:10
|
LL | #[derive(my_macro_attr)]
| ^^^^^^^^^^^^^ not a derive macro
| ^^^^^^^^^^^^^
| |
| not a derive macro
| help: Remove from the surrounding `derive()`
|
help: remove the surrounding "derive()":
--> $DIR/macro-namespace-reserved-2.rs:53:3
|
LL | #[derive(my_macro_attr)]
| ^^^^^^^ ^
= help: Add as non-Derive macro
`#[my_macro_attr]`
error: can't use a procedural macro from the same crate that defines it
--> $DIR/macro-namespace-reserved-2.rs:56:10
@ -92,13 +92,13 @@ error: expected derive macro, found macro `crate::my_macro`
--> $DIR/macro-namespace-reserved-2.rs:50:10
|
LL | #[derive(crate::my_macro)]
| ^^^^^^^^^^^^^^^ not a derive macro
| ^^^^^^^^^^^^^^^
| |
| not a derive macro
| help: Remove from the surrounding `derive()`
|
help: remove the surrounding "derive()":
--> $DIR/macro-namespace-reserved-2.rs:50:3
|
LL | #[derive(crate::my_macro)]
| ^^^^^^^ ^
= help: Add as non-Derive macro
`#[crate::my_macro]`
error: cannot find macro `my_macro_attr` in this scope
--> $DIR/macro-namespace-reserved-2.rs:28:5

View File

@ -2,13 +2,13 @@ error: expected derive macro, found tool attribute `rustfmt::skip`
--> $DIR/tool-attributes-misplaced-2.rs:1:10
|
LL | #[derive(rustfmt::skip)]
| ^^^^^^^^^^^^^ not a derive macro
| ^^^^^^^^^^^^^
| |
| not a derive macro
| help: Remove from the surrounding `derive()`
|
help: remove the surrounding "derive()":
--> $DIR/tool-attributes-misplaced-2.rs:1:3
|
LL | #[derive(rustfmt::skip)]
| ^^^^^^^ ^
= help: Add as non-Derive macro
`#[rustfmt::skip]`
error: expected macro, found tool attribute `rustfmt::skip`
--> $DIR/tool-attributes-misplaced-2.rs:5:5