resolve: Move collection of all macro_rules in the crate to rustdoc

This commit is contained in:
Vadim Petrochenkov 2022-05-13 21:36:36 +03:00
parent 6c5c7f503e
commit 9ba5281c76
3 changed files with 13 additions and 14 deletions

View file

@ -1268,7 +1268,6 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
};
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));

View file

@ -59,7 +59,7 @@ use rustc_span::{Span, DUMMY_SP};
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 @@ impl<'a> Resolver<'a> {
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 @@ impl<'a> Resolver<'a> {
}
}
// 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 @@ impl<'a> Resolver<'a> {
}
/// 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.