about summary refs log tree commit diff
path: root/compiler/rustc_resolve/src
diff options
context:
space:
mode:
authorTakayuki Maeda <takoyaki0316@gmail.com>2022-06-14 14:58:46 +0900
committerTakayuki Maeda <takoyaki0316@gmail.com>2022-06-14 14:58:46 +0900
commit801725a77b17a0641fcf40a310f491d71b059d80 (patch)
treea0fb1adcf9c110f3ff2db5fbf8198b3bdf6d3d4e /compiler/rustc_resolve/src
parent083721a1a7365d3afe1521cd2661b2201aac0450 (diff)
downloadrust-801725a77b17a0641fcf40a310f491d71b059d80.tar.gz
rust-801725a77b17a0641fcf40a310f491d71b059d80.zip
suggest adding a `#[macro_export]` to a private macro
Diffstat (limited to 'compiler/rustc_resolve/src')
-rw-r--r--compiler/rustc_resolve/src/imports.rs36
1 files changed, 30 insertions, 6 deletions
diff --git a/compiler/rustc_resolve/src/imports.rs b/compiler/rustc_resolve/src/imports.rs
index de83a3a5932..a457169c74b 100644
--- a/compiler/rustc_resolve/src/imports.rs
+++ b/compiler/rustc_resolve/src/imports.rs
@@ -12,7 +12,7 @@ use rustc_ast::NodeId;
 use rustc_data_structures::fx::FxHashSet;
 use rustc_data_structures::intern::Interned;
 use rustc_errors::{pluralize, struct_span_err, Applicability, MultiSpan};
-use rustc_hir::def::{self, PartialRes};
+use rustc_hir::def::{self, DefKind, PartialRes};
 use rustc_middle::metadata::ModChild;
 use rustc_middle::span_bug;
 use rustc_middle::ty;
@@ -922,11 +922,35 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
                         .note(&format!("consider declaring type or module `{}` with `pub`", ident))
                         .emit();
                 } else {
-                    let note_msg =
-                        format!("consider marking `{}` as `pub` in the imported module", ident);
-                    struct_span_err!(self.r.session, import.span, E0364, "{}", error_msg)
-                        .span_note(import.span, &note_msg)
-                        .emit();
+                    let mut err =
+                        struct_span_err!(self.r.session, import.span, E0364, "{error_msg}");
+                    match binding.kind {
+                        NameBindingKind::Res(Res::Def(DefKind::Macro(_), _def_id), _)
+                            // exclude decl_macro
+                            if !self.r.session.features_untracked().decl_macro
+                                || !self
+                                    .r
+                                    .session
+                                    .source_map()
+                                    .span_to_snippet(binding.span)
+                                    .map(|snippet| snippet.starts_with("macro "))
+                                    .unwrap_or(true) =>
+                        {
+                            err.span_help(
+                                binding.span,
+                                "consider adding a `#[macro_export]` to the macro in the imported module",
+                            );
+                        }
+                        _ => {
+                            err.span_note(
+                                import.span,
+                                &format!(
+                                    "consider marking `{ident}` as `pub` in the imported module"
+                                ),
+                            );
+                        }
+                    }
+                    err.emit();
                 }
             }
         }