resolve: Add ParentScope::default
, eliminate dummy_parent_scope
Remove some unnecessary parameters from functions
This commit is contained in:
parent
cfbb60bf6d
commit
1a1557c285
5 changed files with 31 additions and 30 deletions
|
@ -163,8 +163,8 @@ impl<'a> Resolver<'a> {
|
|||
let def_id = module.def_id().unwrap();
|
||||
for child in self.cstore.item_children_untracked(def_id, self.session) {
|
||||
let child = child.map_id(|_| panic!("unexpected id"));
|
||||
BuildReducedGraphVisitor { parent_scope: self.dummy_parent_scope(), r: self }
|
||||
.build_reduced_graph_for_external_crate_res(module, child);
|
||||
BuildReducedGraphVisitor { parent_scope: ParentScope::default(module), r: self }
|
||||
.build_reduced_graph_for_external_crate_res(child);
|
||||
}
|
||||
module.populated.set(true)
|
||||
}
|
||||
|
@ -706,7 +706,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
|
|||
self.r.define(parent, ident, TypeNS, (module, vis, sp, expansion));
|
||||
|
||||
for variant in &(*enum_definition).variants {
|
||||
self.build_reduced_graph_for_variant(variant, module, vis, expansion);
|
||||
self.build_reduced_graph_for_variant(variant, module, vis);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -797,8 +797,8 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
|
|||
fn build_reduced_graph_for_variant(&mut self,
|
||||
variant: &Variant,
|
||||
parent: Module<'a>,
|
||||
vis: ty::Visibility,
|
||||
expn_id: ExpnId) {
|
||||
vis: ty::Visibility) {
|
||||
let expn_id = self.parent_scope.expansion;
|
||||
let ident = variant.ident;
|
||||
|
||||
// Define a name in the type namespace.
|
||||
|
@ -861,11 +861,8 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
|
|||
}
|
||||
|
||||
/// Builds the reduced graph for a single item in an external crate.
|
||||
fn build_reduced_graph_for_external_crate_res(
|
||||
&mut self,
|
||||
parent: Module<'a>,
|
||||
child: Export<ast::NodeId>,
|
||||
) {
|
||||
fn build_reduced_graph_for_external_crate_res(&mut self, child: Export<ast::NodeId>) {
|
||||
let parent = self.parent_scope.module;
|
||||
let Export { ident, res, vis, span } = child;
|
||||
// FIXME: We shouldn't create the gensym here, it should come from metadata,
|
||||
// but metadata cannot encode gensyms currently, so we create it here.
|
||||
|
|
|
@ -501,8 +501,8 @@ impl<'a, 'b> LateResolutionVisitor<'a, '_> {
|
|||
fn new(resolver: &'b mut Resolver<'a>) -> LateResolutionVisitor<'a, 'b> {
|
||||
// During late resolution we only track the module component of the parent scope,
|
||||
// although it may be useful to track other components as well for diagnostics.
|
||||
let parent_scope = resolver.dummy_parent_scope();
|
||||
let graph_root = resolver.graph_root;
|
||||
let parent_scope = ParentScope::default(graph_root);
|
||||
LateResolutionVisitor {
|
||||
r: resolver,
|
||||
parent_scope,
|
||||
|
|
|
@ -130,6 +130,17 @@ pub struct ParentScope<'a> {
|
|||
derives: Vec<ast::Path>,
|
||||
}
|
||||
|
||||
impl<'a> ParentScope<'a> {
|
||||
pub fn default(module: Module<'a>) -> ParentScope<'a> {
|
||||
ParentScope {
|
||||
module,
|
||||
expansion: ExpnId::root(),
|
||||
legacy: LegacyScope::Empty,
|
||||
derives: Vec::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Eq)]
|
||||
struct BindingError {
|
||||
name: Name,
|
||||
|
@ -799,7 +810,7 @@ pub struct Resolver<'a> {
|
|||
|
||||
pub definitions: Definitions,
|
||||
|
||||
graph_root: Module<'a>,
|
||||
pub graph_root: Module<'a>,
|
||||
|
||||
prelude: Option<Module<'a>>,
|
||||
pub extern_prelude: FxHashMap<Ident, ExternPreludeEntry<'a>>,
|
||||
|
@ -995,7 +1006,7 @@ impl<'a> hir::lowering::Resolver for Resolver<'a> {
|
|||
segments,
|
||||
};
|
||||
|
||||
let parent_scope = &self.dummy_parent_scope();
|
||||
let parent_scope = &ParentScope::default(self.graph_root);
|
||||
let res = match self.resolve_ast_path(&path, ns, parent_scope) {
|
||||
Ok(res) => res,
|
||||
Err((span, error)) => {
|
||||
|
@ -1069,7 +1080,7 @@ impl<'a> Resolver<'a> {
|
|||
|
||||
let mut invocations = FxHashMap::default();
|
||||
invocations.insert(ExpnId::root(),
|
||||
arenas.alloc_invocation_data(InvocationData::root(graph_root)));
|
||||
arenas.alloc_invocation_data(InvocationData::default(graph_root)));
|
||||
|
||||
let mut macro_defs = FxHashMap::default();
|
||||
macro_defs.insert(ExpnId::root(), root_def_id);
|
||||
|
@ -2649,7 +2660,7 @@ impl<'a> Resolver<'a> {
|
|||
let def_id = self.definitions.local_def_id(module_id);
|
||||
self.module_map.get(&def_id).copied().unwrap_or(self.graph_root)
|
||||
});
|
||||
let parent_scope = &ParentScope { module, ..self.dummy_parent_scope() };
|
||||
let parent_scope = &ParentScope::default(module);
|
||||
let res = self.resolve_ast_path(&path, ns, parent_scope).map_err(|_| ())?;
|
||||
Ok((path, res))
|
||||
}
|
||||
|
|
|
@ -43,9 +43,9 @@ pub struct InvocationData<'a> {
|
|||
}
|
||||
|
||||
impl<'a> InvocationData<'a> {
|
||||
pub fn root(graph_root: Module<'a>) -> Self {
|
||||
pub fn default(module: Module<'a>) -> Self {
|
||||
InvocationData {
|
||||
module: graph_root,
|
||||
module,
|
||||
parent_legacy_scope: LegacyScope::Empty,
|
||||
output_legacy_scope: Cell::new(None),
|
||||
}
|
||||
|
@ -120,17 +120,13 @@ impl<'a> base::Resolver for Resolver<'a> {
|
|||
}
|
||||
|
||||
fn get_module_scope(&mut self, id: ast::NodeId) -> ExpnId {
|
||||
let span = DUMMY_SP.fresh_expansion(ExpnId::root(), ExpnInfo::default(
|
||||
let expn_id = ExpnId::fresh(ExpnId::root(), Some(ExpnInfo::default(
|
||||
ExpnKind::Macro(MacroKind::Attr, sym::test_case), DUMMY_SP, self.session.edition()
|
||||
));
|
||||
let expn_id = span.ctxt().outer_expn();
|
||||
)));
|
||||
let module = self.module_map[&self.definitions.local_def_id(id)];
|
||||
let invocation_data = self.arenas.alloc_invocation_data(InvocationData::default(module));
|
||||
self.definitions.set_invocation_parent(expn_id, module.def_id().unwrap().index);
|
||||
self.invocations.insert(expn_id, self.arenas.alloc_invocation_data(InvocationData {
|
||||
module,
|
||||
parent_legacy_scope: LegacyScope::Empty,
|
||||
output_legacy_scope: Cell::new(None),
|
||||
}));
|
||||
self.invocations.insert(expn_id, invocation_data);
|
||||
expn_id
|
||||
}
|
||||
|
||||
|
@ -251,10 +247,6 @@ impl<'a> base::Resolver for Resolver<'a> {
|
|||
}
|
||||
|
||||
impl<'a> Resolver<'a> {
|
||||
pub fn dummy_parent_scope(&self) -> ParentScope<'a> {
|
||||
self.invoc_parent_scope(ExpnId::root(), Vec::new())
|
||||
}
|
||||
|
||||
fn invoc_parent_scope(&self, invoc_id: ExpnId, derives: Vec<ast::Path>) -> ParentScope<'a> {
|
||||
let invoc = self.invocations[&invoc_id];
|
||||
ParentScope {
|
||||
|
|
|
@ -4,6 +4,7 @@ use rustc::hir::def_id::DefId;
|
|||
use rustc::hir;
|
||||
use rustc::lint as lint;
|
||||
use rustc::ty;
|
||||
use rustc_resolve::ParentScope;
|
||||
use syntax;
|
||||
use syntax::ast::{self, Ident};
|
||||
use syntax::ext::base::SyntaxExtensionKind;
|
||||
|
@ -431,7 +432,7 @@ fn macro_resolve(cx: &DocContext<'_>, path_str: &str) -> Option<Res> {
|
|||
let path = ast::Path::from_ident(Ident::from_str(path_str));
|
||||
cx.enter_resolver(|resolver| {
|
||||
if let Ok((Some(ext), res)) = resolver.resolve_macro_path(
|
||||
&path, None, &resolver.dummy_parent_scope(), false, false
|
||||
&path, None, &ParentScope::default(resolver.graph_root), false, false
|
||||
) {
|
||||
if let SyntaxExtensionKind::LegacyBang { .. } = ext.kind {
|
||||
return Some(res.map_id(|_| panic!("unexpected id")));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue