Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-def/src/nameres/collector.rs')
-rw-r--r--crates/hir-def/src/nameres/collector.rs65
1 files changed, 39 insertions, 26 deletions
diff --git a/crates/hir-def/src/nameres/collector.rs b/crates/hir-def/src/nameres/collector.rs
index c048716d74..eef54fc492 100644
--- a/crates/hir-def/src/nameres/collector.rs
+++ b/crates/hir-def/src/nameres/collector.rs
@@ -38,7 +38,7 @@ use crate::{
self, ExternCrate, Fields, FileItemTreeId, ImportKind, ItemTree, ItemTreeId, ItemTreeNode,
MacroCall, MacroDef, MacroRules, Mod, ModItem, ModKind, TreeId,
},
- macro_call_as_call_id, macro_id_to_def_id,
+ macro_call_as_call_id, macro_call_as_call_id_with_eager, macro_id_to_def_id,
nameres::{
diagnostics::DefDiagnostic,
mod_resolution::ModDir,
@@ -52,10 +52,10 @@ use crate::{
tt,
visibility::{RawVisibility, Visibility},
AdtId, AstId, AstIdWithPath, ConstLoc, CrateRootModuleId, EnumLoc, EnumVariantId,
- ExternBlockLoc, ExternCrateLoc, FunctionId, FunctionLoc, ImplLoc, ImportLoc, Intern,
- ItemContainerId, LocalModuleId, Macro2Id, Macro2Loc, MacroExpander, MacroId, MacroRulesId,
- MacroRulesLoc, ModuleDefId, ModuleId, ProcMacroId, ProcMacroLoc, StaticLoc, StructLoc,
- TraitAliasLoc, TraitLoc, TypeAliasLoc, UnionLoc, UnresolvedMacro,
+ ExternBlockLoc, ExternCrateLoc, FunctionId, FunctionLoc, ImplLoc, Intern, ItemContainerId,
+ LocalModuleId, Macro2Id, Macro2Loc, MacroExpander, MacroId, MacroRulesId, MacroRulesLoc,
+ ModuleDefId, ModuleId, ProcMacroId, ProcMacroLoc, StaticLoc, StructLoc, TraitAliasLoc,
+ TraitLoc, TypeAliasLoc, UnionLoc, UnresolvedMacro, UseLoc,
};
static GLOB_RECURSION_LIMIT: Limit = Limit::new(100);
@@ -146,7 +146,7 @@ impl PartialResolvedImport {
#[derive(Clone, Debug, Eq, PartialEq)]
enum ImportSource {
- Import { id: ItemTreeId<item_tree::Import>, use_tree: Idx<ast::UseTree> },
+ Use { id: ItemTreeId<item_tree::Use>, use_tree: Idx<ast::UseTree> },
ExternCrate(ItemTreeId<item_tree::ExternCrate>),
}
@@ -166,7 +166,7 @@ impl Import {
db: &dyn DefDatabase,
krate: CrateId,
tree: &ItemTree,
- id: ItemTreeId<item_tree::Import>,
+ id: ItemTreeId<item_tree::Use>,
mut cb: impl FnMut(Self),
) {
let it = &tree[id.value];
@@ -181,7 +181,7 @@ impl Import {
kind,
is_prelude,
is_macro_use: false,
- source: ImportSource::Import { id, use_tree: idx },
+ source: ImportSource::Use { id, use_tree: idx },
});
});
}
@@ -1474,7 +1474,7 @@ impl DefCollector<'_> {
}
for directive in &self.unresolved_imports {
- if let ImportSource::Import { id: import, use_tree } = directive.import.source {
+ if let ImportSource::Use { id: import, use_tree } = directive.import.source {
if matches!(
(directive.import.path.segments().first(), &directive.import.path.kind),
(Some(krate), PathKind::Plain | PathKind::Abs) if diagnosed_extern_crates.contains(krate)
@@ -1576,12 +1576,10 @@ impl ModCollector<'_, '_> {
match item {
ModItem::Mod(m) => self.collect_module(m, &attrs),
- ModItem::Import(import_id) => {
- let _import_id = ImportLoc {
- container: module,
- id: ItemTreeId::new(self.tree_id, import_id),
- }
- .intern(db);
+ ModItem::Use(import_id) => {
+ let _import_id =
+ UseLoc { container: module, id: ItemTreeId::new(self.tree_id, import_id) }
+ .intern(db);
Import::from_use(
db,
krate,
@@ -2187,7 +2185,7 @@ impl ModCollector<'_, '_> {
// scopes without eager expansion.
// Case 1: try to resolve macro calls with single-segment name and expand macro_rules
- if let Ok(res) = macro_call_as_call_id(
+ if let Ok(res) = macro_call_as_call_id_with_eager(
db.upcast(),
&ast_id,
mac.expand_to,
@@ -2210,19 +2208,34 @@ impl ModCollector<'_, '_> {
.map(|it| macro_id_to_def_id(self.def_collector.db, it))
})
},
- ) {
- // Legacy macros need to be expanded immediately, so that any macros they produce
- // are in scope.
- if let Some(val) = res {
- self.def_collector.collect_macro_expansion(
+ |path| {
+ let resolved_res = self.def_collector.def_map.resolve_path_fp_with_macro(
+ db,
+ ResolveMode::Other,
self.module_id,
- val,
- self.macro_depth + 1,
- container,
+ &path,
+ BuiltinShadowMode::Module,
+ Some(MacroSubNs::Bang),
);
- }
+ resolved_res.resolved_def.take_macros().map(|it| macro_id_to_def_id(db, it))
+ },
+ ) {
+ // FIXME: if there were errors, this mightve been in the eager expansion from an
+ // unresolved macro, so we need to push this into late macro resolution. see fixme above
+ if res.err.is_none() {
+ // Legacy macros need to be expanded immediately, so that any macros they produce
+ // are in scope.
+ if let Some(val) = res.value {
+ self.def_collector.collect_macro_expansion(
+ self.module_id,
+ val,
+ self.macro_depth + 1,
+ container,
+ );
+ }
- return;
+ return;
+ }
}
// Case 2: resolve in module scope, expand during name resolution.