Skip to content

Commit fed6131

Browse files
committed
Add note to 'macro not found' to point to identically-named imports.
1 parent 5998c2e commit fed6131

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

compiler/rustc_resolve/src/macros.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use rustc_expand::base::{SyntaxExtension, SyntaxExtensionKind};
1919
use rustc_expand::compile_declarative_macro;
2020
use rustc_expand::expand::{AstFragment, Invocation, InvocationKind, SupportsMacroExpansion};
2121
use rustc_feature::is_builtin_attr_name;
22-
use rustc_hir::def::{self, DefKind, NonMacroAttrKind};
22+
use rustc_hir::def::{self, DefKind, Namespace, NonMacroAttrKind};
2323
use rustc_hir::def_id::{CrateNum, LocalDefId};
2424
use rustc_hir::PrimTy;
2525
use rustc_middle::middle::stability;
@@ -1115,6 +1115,24 @@ impl<'a> Resolver<'a> {
11151115
let msg = format!("cannot find {} `{}` in this scope", expected, ident);
11161116
let mut err = self.session.struct_span_err(ident.span, &msg);
11171117
self.unresolved_macro_suggestions(&mut err, kind, &parent_scope, ident);
1118+
if let Ok(binding) = self.early_resolve_ident_in_lexical_scope(
1119+
ident,
1120+
ScopeSet::All(Namespace::TypeNS, false),
1121+
&parent_scope,
1122+
false,
1123+
false,
1124+
ident.span,
1125+
) {
1126+
if let crate::NameBindingKind::Import { import, .. } = binding.kind {
1127+
err.span_note(
1128+
import.span,
1129+
&format!(
1130+
"`{}` is imported here, but it is not a {}",
1131+
ident, expected
1132+
),
1133+
);
1134+
}
1135+
}
11181136
err.emit();
11191137
}
11201138
}

0 commit comments

Comments
 (0)