resolve: Move collection of all macro_rules
in the crate to rustdoc
This commit is contained in:
parent
6c5c7f503e
commit
9ba5281c76
@ -1268,7 +1268,6 @@ fn define_macro(&mut self, item: &ast::Item) -> MacroRulesScopeRef<'a> {
|
||||
};
|
||||
let binding = (res, vis, span, expansion).to_name_binding(self.r.arenas);
|
||||
self.r.set_binding_parent_module(binding, parent_scope.module);
|
||||
self.r.all_macro_rules.insert(ident.name, res);
|
||||
if is_macro_export {
|
||||
let module = self.r.graph_root;
|
||||
self.r.define(module, ident, MacroNS, (res, vis, span, expansion, IsMacroExport));
|
||||
|
@ -59,7 +59,7 @@
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::collections::BTreeSet;
|
||||
use std::{cmp, fmt, mem, ptr};
|
||||
use std::{cmp, fmt, ptr};
|
||||
use tracing::debug;
|
||||
|
||||
use diagnostics::{ImportSuggestion, LabelSuggestion, Suggestion};
|
||||
@ -966,8 +966,6 @@ pub struct Resolver<'a> {
|
||||
registered_attrs: FxHashSet<Ident>,
|
||||
registered_tools: RegisteredTools,
|
||||
macro_use_prelude: FxHashMap<Symbol, &'a NameBinding<'a>>,
|
||||
/// FIXME: The only user of this is a doc link resolution hack for rustdoc.
|
||||
all_macro_rules: FxHashMap<Symbol, Res>,
|
||||
macro_map: FxHashMap<DefId, Lrc<SyntaxExtension>>,
|
||||
dummy_ext_bang: Lrc<SyntaxExtension>,
|
||||
dummy_ext_derive: Lrc<SyntaxExtension>,
|
||||
@ -1360,7 +1358,6 @@ pub fn new(
|
||||
registered_attrs,
|
||||
registered_tools,
|
||||
macro_use_prelude: FxHashMap::default(),
|
||||
all_macro_rules: Default::default(),
|
||||
macro_map: FxHashMap::default(),
|
||||
dummy_ext_bang: Lrc::new(SyntaxExtension::dummy_bang(session.edition())),
|
||||
dummy_ext_derive: Lrc::new(SyntaxExtension::dummy_derive(session.edition())),
|
||||
@ -1912,11 +1909,6 @@ pub fn resolve_rustdoc_path(
|
||||
}
|
||||
}
|
||||
|
||||
// For rustdoc.
|
||||
pub fn take_all_macro_rules(&mut self) -> FxHashMap<Symbol, Res> {
|
||||
mem::take(&mut self.all_macro_rules)
|
||||
}
|
||||
|
||||
/// For rustdoc.
|
||||
/// For local modules returns only reexports, for external modules returns all children.
|
||||
pub fn module_children_or_reexports(&self, def_id: DefId) -> Vec<ModChild> {
|
||||
@ -1928,8 +1920,12 @@ pub fn module_children_or_reexports(&self, def_id: DefId) -> Vec<ModChild> {
|
||||
}
|
||||
|
||||
/// For rustdoc.
|
||||
pub fn macro_rules_scope(&self, def_id: LocalDefId) -> MacroRulesScopeRef<'a> {
|
||||
*self.macro_rules_scopes.get(&def_id).expect("not a `macro_rules` item")
|
||||
pub fn macro_rules_scope(&self, def_id: LocalDefId) -> (MacroRulesScopeRef<'a>, Res) {
|
||||
let scope = *self.macro_rules_scopes.get(&def_id).expect("not a `macro_rules` item");
|
||||
match scope.get() {
|
||||
MacroRulesScope::Binding(mb) => (scope, mb.binding.res()),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Retrieves the span of the given `DefId` if `DefId` is in the local crate.
|
||||
|
@ -40,6 +40,7 @@
|
||||
traits_in_scope: Default::default(),
|
||||
all_traits: Default::default(),
|
||||
all_trait_impls: Default::default(),
|
||||
all_macro_rules: Default::default(),
|
||||
document_private_items,
|
||||
};
|
||||
|
||||
@ -64,7 +65,7 @@
|
||||
traits_in_scope: link_resolver.traits_in_scope,
|
||||
all_traits: Some(link_resolver.all_traits),
|
||||
all_trait_impls: Some(link_resolver.all_trait_impls),
|
||||
all_macro_rules: link_resolver.resolver.take_all_macro_rules(),
|
||||
all_macro_rules: link_resolver.all_macro_rules,
|
||||
}
|
||||
}
|
||||
|
||||
@ -82,6 +83,7 @@ struct EarlyDocLinkResolver<'r, 'ra> {
|
||||
traits_in_scope: DefIdMap<Vec<TraitCandidate>>,
|
||||
all_traits: Vec<DefId>,
|
||||
all_trait_impls: Vec<DefId>,
|
||||
all_macro_rules: FxHashMap<Symbol, Res<ast::NodeId>>,
|
||||
document_private_items: bool,
|
||||
}
|
||||
|
||||
@ -339,8 +341,10 @@ fn visit_item(&mut self, item: &ast::Item) {
|
||||
self.all_trait_impls.push(self.resolver.local_def_id(item.id).to_def_id());
|
||||
}
|
||||
ItemKind::MacroDef(macro_def) if macro_def.macro_rules => {
|
||||
self.parent_scope.macro_rules =
|
||||
let (macro_rules_scope, res) =
|
||||
self.resolver.macro_rules_scope(self.resolver.local_def_id(item.id));
|
||||
self.parent_scope.macro_rules = macro_rules_scope;
|
||||
self.all_macro_rules.insert(item.ident.name, res);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user