From fed6131c4185aabcd8fa3e28851373944a407d21 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Sun, 22 Aug 2021 13:35:51 +0200 Subject: [PATCH] Add note to 'macro not found' to point to identically-named imports. --- compiler/rustc_resolve/src/macros.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_resolve/src/macros.rs b/compiler/rustc_resolve/src/macros.rs index 7f86f891c44..89b153a6c0e 100644 --- a/compiler/rustc_resolve/src/macros.rs +++ b/compiler/rustc_resolve/src/macros.rs @@ -19,7 +19,7 @@ use rustc_expand::base::{SyntaxExtension, SyntaxExtensionKind}; use rustc_expand::compile_declarative_macro; use rustc_expand::expand::{AstFragment, Invocation, InvocationKind, SupportsMacroExpansion}; use rustc_feature::is_builtin_attr_name; -use rustc_hir::def::{self, DefKind, NonMacroAttrKind}; +use rustc_hir::def::{self, DefKind, Namespace, NonMacroAttrKind}; use rustc_hir::def_id::{CrateNum, LocalDefId}; use rustc_hir::PrimTy; use rustc_middle::middle::stability; @@ -1115,6 +1115,24 @@ impl<'a> Resolver<'a> { let msg = format!("cannot find {} `{}` in this scope", expected, ident); let mut err = self.session.struct_span_err(ident.span, &msg); self.unresolved_macro_suggestions(&mut err, kind, &parent_scope, ident); + if let Ok(binding) = self.early_resolve_ident_in_lexical_scope( + ident, + ScopeSet::All(Namespace::TypeNS, false), + &parent_scope, + false, + false, + ident.span, + ) { + if let crate::NameBindingKind::Import { import, .. } = binding.kind { + err.span_note( + import.span, + &format!( + "`{}` is imported here, but it is not a {}", + ident, expected + ), + ); + } + } err.emit(); } }