Skip to content

Commit 1a1557c

Browse files
committed
resolve: Add ParentScope::default, eliminate dummy_parent_scope
Remove some unnecessary parameters from functions
1 parent cfbb60b commit 1a1557c

File tree

5 files changed

+31
-30
lines changed

5 files changed

+31
-30
lines changed

src/librustc_resolve/build_reduced_graph.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ impl<'a> Resolver<'a> {
163163
let def_id = module.def_id().unwrap();
164164
for child in self.cstore.item_children_untracked(def_id, self.session) {
165165
let child = child.map_id(|_| panic!("unexpected id"));
166-
BuildReducedGraphVisitor { parent_scope: self.dummy_parent_scope(), r: self }
167-
.build_reduced_graph_for_external_crate_res(module, child);
166+
BuildReducedGraphVisitor { parent_scope: ParentScope::default(module), r: self }
167+
.build_reduced_graph_for_external_crate_res(child);
168168
}
169169
module.populated.set(true)
170170
}
@@ -706,7 +706,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
706706
self.r.define(parent, ident, TypeNS, (module, vis, sp, expansion));
707707

708708
for variant in &(*enum_definition).variants {
709-
self.build_reduced_graph_for_variant(variant, module, vis, expansion);
709+
self.build_reduced_graph_for_variant(variant, module, vis);
710710
}
711711
}
712712

@@ -797,8 +797,8 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
797797
fn build_reduced_graph_for_variant(&mut self,
798798
variant: &Variant,
799799
parent: Module<'a>,
800-
vis: ty::Visibility,
801-
expn_id: ExpnId) {
800+
vis: ty::Visibility) {
801+
let expn_id = self.parent_scope.expansion;
802802
let ident = variant.ident;
803803

804804
// Define a name in the type namespace.
@@ -861,11 +861,8 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
861861
}
862862

863863
/// Builds the reduced graph for a single item in an external crate.
864-
fn build_reduced_graph_for_external_crate_res(
865-
&mut self,
866-
parent: Module<'a>,
867-
child: Export<ast::NodeId>,
868-
) {
864+
fn build_reduced_graph_for_external_crate_res(&mut self, child: Export<ast::NodeId>) {
865+
let parent = self.parent_scope.module;
869866
let Export { ident, res, vis, span } = child;
870867
// FIXME: We shouldn't create the gensym here, it should come from metadata,
871868
// but metadata cannot encode gensyms currently, so we create it here.

src/librustc_resolve/late.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,8 +501,8 @@ impl<'a, 'b> LateResolutionVisitor<'a, '_> {
501501
fn new(resolver: &'b mut Resolver<'a>) -> LateResolutionVisitor<'a, 'b> {
502502
// During late resolution we only track the module component of the parent scope,
503503
// although it may be useful to track other components as well for diagnostics.
504-
let parent_scope = resolver.dummy_parent_scope();
505504
let graph_root = resolver.graph_root;
505+
let parent_scope = ParentScope::default(graph_root);
506506
LateResolutionVisitor {
507507
r: resolver,
508508
parent_scope,

src/librustc_resolve/lib.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,17 @@ pub struct ParentScope<'a> {
130130
derives: Vec<ast::Path>,
131131
}
132132

133+
impl<'a> ParentScope<'a> {
134+
pub fn default(module: Module<'a>) -> ParentScope<'a> {
135+
ParentScope {
136+
module,
137+
expansion: ExpnId::root(),
138+
legacy: LegacyScope::Empty,
139+
derives: Vec::new(),
140+
}
141+
}
142+
}
143+
133144
#[derive(Eq)]
134145
struct BindingError {
135146
name: Name,
@@ -799,7 +810,7 @@ pub struct Resolver<'a> {
799810

800811
pub definitions: Definitions,
801812

802-
graph_root: Module<'a>,
813+
pub graph_root: Module<'a>,
803814

804815
prelude: Option<Module<'a>>,
805816
pub extern_prelude: FxHashMap<Ident, ExternPreludeEntry<'a>>,
@@ -995,7 +1006,7 @@ impl<'a> hir::lowering::Resolver for Resolver<'a> {
9951006
segments,
9961007
};
9971008

998-
let parent_scope = &self.dummy_parent_scope();
1009+
let parent_scope = &ParentScope::default(self.graph_root);
9991010
let res = match self.resolve_ast_path(&path, ns, parent_scope) {
10001011
Ok(res) => res,
10011012
Err((span, error)) => {
@@ -1069,7 +1080,7 @@ impl<'a> Resolver<'a> {
10691080

10701081
let mut invocations = FxHashMap::default();
10711082
invocations.insert(ExpnId::root(),
1072-
arenas.alloc_invocation_data(InvocationData::root(graph_root)));
1083+
arenas.alloc_invocation_data(InvocationData::default(graph_root)));
10731084

10741085
let mut macro_defs = FxHashMap::default();
10751086
macro_defs.insert(ExpnId::root(), root_def_id);
@@ -2649,7 +2660,7 @@ impl<'a> Resolver<'a> {
26492660
let def_id = self.definitions.local_def_id(module_id);
26502661
self.module_map.get(&def_id).copied().unwrap_or(self.graph_root)
26512662
});
2652-
let parent_scope = &ParentScope { module, ..self.dummy_parent_scope() };
2663+
let parent_scope = &ParentScope::default(module);
26532664
let res = self.resolve_ast_path(&path, ns, parent_scope).map_err(|_| ())?;
26542665
Ok((path, res))
26552666
}

src/librustc_resolve/macros.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ pub struct InvocationData<'a> {
4343
}
4444

4545
impl<'a> InvocationData<'a> {
46-
pub fn root(graph_root: Module<'a>) -> Self {
46+
pub fn default(module: Module<'a>) -> Self {
4747
InvocationData {
48-
module: graph_root,
48+
module,
4949
parent_legacy_scope: LegacyScope::Empty,
5050
output_legacy_scope: Cell::new(None),
5151
}
@@ -120,17 +120,13 @@ impl<'a> base::Resolver for Resolver<'a> {
120120
}
121121

122122
fn get_module_scope(&mut self, id: ast::NodeId) -> ExpnId {
123-
let span = DUMMY_SP.fresh_expansion(ExpnId::root(), ExpnInfo::default(
123+
let expn_id = ExpnId::fresh(ExpnId::root(), Some(ExpnInfo::default(
124124
ExpnKind::Macro(MacroKind::Attr, sym::test_case), DUMMY_SP, self.session.edition()
125-
));
126-
let expn_id = span.ctxt().outer_expn();
125+
)));
127126
let module = self.module_map[&self.definitions.local_def_id(id)];
127+
let invocation_data = self.arenas.alloc_invocation_data(InvocationData::default(module));
128128
self.definitions.set_invocation_parent(expn_id, module.def_id().unwrap().index);
129-
self.invocations.insert(expn_id, self.arenas.alloc_invocation_data(InvocationData {
130-
module,
131-
parent_legacy_scope: LegacyScope::Empty,
132-
output_legacy_scope: Cell::new(None),
133-
}));
129+
self.invocations.insert(expn_id, invocation_data);
134130
expn_id
135131
}
136132

@@ -251,10 +247,6 @@ impl<'a> base::Resolver for Resolver<'a> {
251247
}
252248

253249
impl<'a> Resolver<'a> {
254-
pub fn dummy_parent_scope(&self) -> ParentScope<'a> {
255-
self.invoc_parent_scope(ExpnId::root(), Vec::new())
256-
}
257-
258250
fn invoc_parent_scope(&self, invoc_id: ExpnId, derives: Vec<ast::Path>) -> ParentScope<'a> {
259251
let invoc = self.invocations[&invoc_id];
260252
ParentScope {

src/librustdoc/passes/collect_intra_doc_links.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use rustc::hir::def_id::DefId;
44
use rustc::hir;
55
use rustc::lint as lint;
66
use rustc::ty;
7+
use rustc_resolve::ParentScope;
78
use syntax;
89
use syntax::ast::{self, Ident};
910
use syntax::ext::base::SyntaxExtensionKind;
@@ -431,7 +432,7 @@ fn macro_resolve(cx: &DocContext<'_>, path_str: &str) -> Option<Res> {
431432
let path = ast::Path::from_ident(Ident::from_str(path_str));
432433
cx.enter_resolver(|resolver| {
433434
if let Ok((Some(ext), res)) = resolver.resolve_macro_path(
434-
&path, None, &resolver.dummy_parent_scope(), false, false
435+
&path, None, &ParentScope::default(resolver.graph_root), false, false
435436
) {
436437
if let SyntaxExtensionKind::LegacyBang { .. } = ext.kind {
437438
return Some(res.map_id(|_| panic!("unexpected id")));

0 commit comments

Comments
 (0)