Add suggestion to remove derive() if invoked macro is non-derive
This commit is contained in:
parent
89c2e3d3d7
commit
42f2be8a8c
4 changed files with 41 additions and 5 deletions
|
@ -544,11 +544,23 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
if let Some((article, expected)) = unexpected_res {
|
if let Some((article, expected)) = unexpected_res {
|
||||||
let path_str = pprust::path_to_string(path);
|
let path_str = pprust::path_to_string(path);
|
||||||
let msg = format!("expected {}, found {} `{}`", expected, res.descr(), path_str);
|
let msg = format!("expected {}, found {} `{}`", expected, res.descr(), path_str);
|
||||||
self.tcx
|
let mut err = self.tcx.sess.struct_span_err(path.span, &msg);
|
||||||
.sess
|
|
||||||
.struct_span_err(path.span, &msg)
|
err.span_label(path.span, format!("not {} {}", article, expected));
|
||||||
.span_label(path.span, format!("not {} {}", article, expected))
|
|
||||||
.emit();
|
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()\":",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
err.emit();
|
||||||
return Ok((self.dummy_ext(kind), Res::Err));
|
return Ok((self.dummy_ext(kind), Res::Err));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,12 @@ error: expected derive macro, found built-in attribute `inline`
|
||||||
|
|
|
|
||||||
LL | #[derive(inline)]
|
LL | #[derive(inline)]
|
||||||
| ^^^^^^ not a derive macro
|
| ^^^^^^ not a derive macro
|
||||||
|
|
|
||||||
|
help: remove the surrounding "derive()":
|
||||||
|
--> $DIR/macro-path-prelude-fail-4.rs:1:3
|
||||||
|
|
|
||||||
|
LL | #[derive(inline)]
|
||||||
|
| ^^^^^^^ ^
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
|
|
@ -57,6 +57,12 @@ error: expected derive macro, found attribute macro `my_macro_attr`
|
||||||
|
|
|
|
||||||
LL | #[derive(my_macro_attr)]
|
LL | #[derive(my_macro_attr)]
|
||||||
| ^^^^^^^^^^^^^ not a derive macro
|
| ^^^^^^^^^^^^^ not a derive macro
|
||||||
|
|
|
||||||
|
help: remove the surrounding "derive()":
|
||||||
|
--> $DIR/macro-namespace-reserved-2.rs:53:3
|
||||||
|
|
|
||||||
|
LL | #[derive(my_macro_attr)]
|
||||||
|
| ^^^^^^^ ^
|
||||||
|
|
||||||
error: can't use a procedural macro from the same crate that defines it
|
error: can't use a procedural macro from the same crate that defines it
|
||||||
--> $DIR/macro-namespace-reserved-2.rs:56:10
|
--> $DIR/macro-namespace-reserved-2.rs:56:10
|
||||||
|
@ -87,6 +93,12 @@ error: expected derive macro, found macro `crate::my_macro`
|
||||||
|
|
|
|
||||||
LL | #[derive(crate::my_macro)]
|
LL | #[derive(crate::my_macro)]
|
||||||
| ^^^^^^^^^^^^^^^ not a derive macro
|
| ^^^^^^^^^^^^^^^ not a derive macro
|
||||||
|
|
|
||||||
|
help: remove the surrounding "derive()":
|
||||||
|
--> $DIR/macro-namespace-reserved-2.rs:50:3
|
||||||
|
|
|
||||||
|
LL | #[derive(crate::my_macro)]
|
||||||
|
| ^^^^^^^ ^
|
||||||
|
|
||||||
error: cannot find macro `my_macro_attr` in this scope
|
error: cannot find macro `my_macro_attr` in this scope
|
||||||
--> $DIR/macro-namespace-reserved-2.rs:28:5
|
--> $DIR/macro-namespace-reserved-2.rs:28:5
|
||||||
|
|
|
@ -3,6 +3,12 @@ error: expected derive macro, found tool attribute `rustfmt::skip`
|
||||||
|
|
|
|
||||||
LL | #[derive(rustfmt::skip)]
|
LL | #[derive(rustfmt::skip)]
|
||||||
| ^^^^^^^^^^^^^ not a derive macro
|
| ^^^^^^^^^^^^^ not a derive macro
|
||||||
|
|
|
||||||
|
help: remove the surrounding "derive()":
|
||||||
|
--> $DIR/tool-attributes-misplaced-2.rs:1:3
|
||||||
|
|
|
||||||
|
LL | #[derive(rustfmt::skip)]
|
||||||
|
| ^^^^^^^ ^
|
||||||
|
|
||||||
error: expected macro, found tool attribute `rustfmt::skip`
|
error: expected macro, found tool attribute `rustfmt::skip`
|
||||||
--> $DIR/tool-attributes-misplaced-2.rs:5:5
|
--> $DIR/tool-attributes-misplaced-2.rs:5:5
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue