Make "consider importing" consistent for macros
This commit is contained in:
parent
8b35c0bb0f
commit
5bd8ba8493
10 changed files with 53 additions and 27 deletions
|
@ -1352,6 +1352,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
macro_kind: MacroKind,
|
||||
parent_scope: &ParentScope<'a>,
|
||||
ident: Ident,
|
||||
krate: &Crate,
|
||||
) {
|
||||
let is_expected = &|res: Res| res.macro_kind() == Some(macro_kind);
|
||||
let suggestion = self.early_lookup_typo_candidate(
|
||||
|
@ -1364,13 +1365,17 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
|
||||
let import_suggestions =
|
||||
self.lookup_import_candidates(ident, Namespace::MacroNS, parent_scope, is_expected);
|
||||
let (span, found_use) = match parent_scope.module.nearest_parent_mod().as_local() {
|
||||
Some(def_id) => UsePlacementFinder::check(krate, self.def_id_to_node_id[def_id]),
|
||||
None => (None, FoundUse::No),
|
||||
};
|
||||
show_candidates(
|
||||
self.tcx,
|
||||
err,
|
||||
None,
|
||||
span,
|
||||
&import_suggestions,
|
||||
Instead::No,
|
||||
FoundUse::Yes,
|
||||
found_use,
|
||||
DiagnosticMode::Normal,
|
||||
vec![],
|
||||
"",
|
||||
|
|
|
@ -1522,7 +1522,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
self.tcx.sess.time("check_hidden_glob_reexports", || {
|
||||
self.check_hidden_glob_reexports(exported_ambiguities)
|
||||
});
|
||||
self.tcx.sess.time("finalize_macro_resolutions", || self.finalize_macro_resolutions());
|
||||
self.tcx
|
||||
.sess
|
||||
.time("finalize_macro_resolutions", || self.finalize_macro_resolutions(krate));
|
||||
self.tcx.sess.time("late_resolve_crate", || self.late_resolve_crate(krate));
|
||||
self.tcx.sess.time("resolve_main", || self.resolve_main());
|
||||
self.tcx.sess.time("resolve_check_unused", || self.check_unused(krate));
|
||||
|
|
|
@ -7,7 +7,7 @@ use crate::{BuiltinMacroState, Determinacy};
|
|||
use crate::{DeriveData, Finalize, ParentScope, ResolutionError, Resolver, ScopeSet};
|
||||
use crate::{ModuleKind, ModuleOrUniformRoot, NameBinding, PathResult, Segment};
|
||||
use rustc_ast::expand::StrippedCfgItem;
|
||||
use rustc_ast::{self as ast, attr, Inline, ItemKind, ModKind, NodeId};
|
||||
use rustc_ast::{self as ast, attr, Crate, Inline, ItemKind, ModKind, NodeId};
|
||||
use rustc_ast_pretty::pprust;
|
||||
use rustc_attr::StabilityLevel;
|
||||
use rustc_data_structures::intern::Interned;
|
||||
|
@ -674,7 +674,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
res.map(|res| (self.get_macro(res).map(|macro_data| macro_data.ext), res))
|
||||
}
|
||||
|
||||
pub(crate) fn finalize_macro_resolutions(&mut self) {
|
||||
pub(crate) fn finalize_macro_resolutions(&mut self, krate: &Crate) {
|
||||
let check_consistency = |this: &mut Self,
|
||||
path: &[Segment],
|
||||
span,
|
||||
|
@ -795,7 +795,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
let expected = kind.descr_expected();
|
||||
let msg = format!("cannot find {} `{}` in this scope", expected, ident);
|
||||
let mut err = self.tcx.sess.struct_span_err(ident.span, msg);
|
||||
self.unresolved_macro_suggestions(&mut err, kind, &parent_scope, ident);
|
||||
self.unresolved_macro_suggestions(&mut err, kind, &parent_scope, ident, krate);
|
||||
err.emit();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue