//! path and, upon success, we run macro expansion and "collect module" phase on
//! the result
+pub mod attr_resolution;
pub mod diagnostics;
mod collector;
mod mod_resolution;
use profile::Count;
use rustc_hash::FxHashMap;
use stdx::format_to;
-use syntax::ast;
+use syntax::{ast, SmolStr};
use crate::{
db::DefDatabase,
item_scope::{BuiltinShadowMode, ItemScope},
+ item_tree::TreeId,
nameres::{diagnostics::DefDiagnostic, path_resolution::ResolveMode},
path::ModPath,
per_ns::PerNs,
/// (the primary purpose is to resolve derive helpers and fetch a proc-macros name)
exported_proc_macros: FxHashMap<MacroDefId, ProcMacroDef>,
+ /// Custom attributes registered with `#![register_attr]`.
+ registered_attrs: Vec<SmolStr>,
+ /// Custom tool modules registered with `#![register_tool]`.
+ registered_tools: Vec<SmolStr>,
+
edition: Edition,
+ recursion_limit: Option<u32>,
diagnostics: Vec<DefDiagnostic>,
}
}
impl ModuleOrigin {
- fn declaration(&self) -> Option<AstId<ast::Module>> {
+ pub fn declaration(&self) -> Option<AstId<ast::Module>> {
match self {
ModuleOrigin::File { declaration: module, .. }
| ModuleOrigin::Inline { definition: module, .. } => Some(*module),
let edition = crate_graph[krate].edition;
let origin = ModuleOrigin::CrateRoot { definition: crate_graph[krate].root_file_id };
let def_map = DefMap::empty(krate, edition, origin);
- let def_map = collector::collect_defs(db, def_map, None);
+ let def_map = collector::collect_defs(
+ db,
+ def_map,
+ TreeId::new(crate_graph[krate].root_file_id.into(), None),
+ );
Arc::new(def_map)
}
) -> Option<Arc<DefMap>> {
let block: BlockLoc = db.lookup_intern_block(block_id);
- let item_tree = db.file_item_tree(block.ast_id.file_id);
- if item_tree.inner_items_of_block(block.ast_id.value).is_empty() {
+ let tree_id = TreeId::new(block.ast_id.file_id, Some(block_id));
+ let item_tree = tree_id.item_tree(db);
+ if item_tree.top_level_items().is_empty() {
return None;
}
);
def_map.block = Some(block_info);
- let def_map = collector::collect_defs(db, def_map, Some(block.ast_id));
+ let def_map = collector::collect_defs(db, def_map, tree_id);
Some(Arc::new(def_map))
}
block: None,
krate,
edition,
+ recursion_limit: None,
extern_prelude: FxHashMap::default(),
exported_proc_macros: FxHashMap::default(),
prelude: None,
root,
modules,
+ registered_attrs: Vec::new(),
+ registered_tools: Vec::new(),
diagnostics: Vec::new(),
}
}
pub fn exported_proc_macros(&self) -> impl Iterator<Item = (MacroDefId, Name)> + '_ {
self.exported_proc_macros.iter().map(|(id, def)| (*id, def.name.clone()))
}
+ pub fn registered_tools(&self) -> &[SmolStr] {
+ &self.registered_tools
+ }
+ pub fn registered_attrs(&self) -> &[SmolStr] {
+ &self.registered_attrs
+ }
pub fn root(&self) -> LocalModuleId {
self.root
}
extern_prelude,
diagnostics,
modules,
+ registered_attrs,
+ registered_tools,
block: _,
edition: _,
+ recursion_limit: _,
krate: _,
prelude: _,
root: _,
exported_proc_macros.shrink_to_fit();
diagnostics.shrink_to_fit();
modules.shrink_to_fit();
+ registered_attrs.shrink_to_fit();
+ registered_tools.shrink_to_fit();
for (_, module) in modules.iter_mut() {
module.children.shrink_to_fit();
module.scope.shrink_to_fit();
pub fn diagnostics(&self) -> &[DefDiagnostic] {
self.diagnostics.as_slice()
}
+
+ pub fn recursion_limit(&self) -> Option<u32> {
+ self.recursion_limit
+ }
}
impl ModuleData {