summary refs log tree commit diff
path: root/compiler/rustc_resolve/src
diff options
context:
space:
mode:
authorTom Martin <tom.martin1239@gmail.com>2023-03-26 15:59:45 +0100
committerTom Martin <tom.martin1239@gmail.com>2023-03-26 16:01:25 +0100
commit42f2be8a8c655695ecf2b56eebf023faf7d62463 (patch)
tree494c2329fd7deff61ad2587f81456e604e0c66d9 /compiler/rustc_resolve/src
parent89c2e3d3d75486e52473de3ae38f0ca6efeffef2 (diff)
downloadrust-42f2be8a8c655695ecf2b56eebf023faf7d62463.tar.gz
rust-42f2be8a8c655695ecf2b56eebf023faf7d62463.zip
Add suggestion to remove derive() if invoked macro is non-derive
Diffstat (limited to 'compiler/rustc_resolve/src')
-rw-r--r--compiler/rustc_resolve/src/macros.rs22
1 files changed, 17 insertions, 5 deletions
diff --git a/compiler/rustc_resolve/src/macros.rs b/compiler/rustc_resolve/src/macros.rs
index 48707d37a10..38e8cf8cd2f 100644
--- a/compiler/rustc_resolve/src/macros.rs
+++ b/compiler/rustc_resolve/src/macros.rs
@@ -544,11 +544,23 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
         if let Some((article, expected)) = unexpected_res {
             let path_str = pprust::path_to_string(path);
             let msg = format!("expected {}, found {} `{}`", expected, res.descr(), path_str);
-            self.tcx
-                .sess
-                .struct_span_err(path.span, &msg)
-                .span_label(path.span, format!("not {} {}", article, expected))
-                .emit();
+            let mut err = self.tcx.sess.struct_span_err(path.span, &msg);
+
+            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()\":",
+                );
+            }
+
+            err.emit();
             return Ok((self.dummy_ext(kind), Res::Err));
         }