Skip to content

Commit 310ee4d

Browse files
committed
resolve: Privatize BuildReducedGraphVisitor
1 parent ea68bc8 commit 310ee4d

File tree

4 files changed

+23
-18
lines changed

4 files changed

+23
-18
lines changed

src/librustc_resolve/build_reduced_graph.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use syntax::attr;
3030
use syntax::ast::{self, Block, ForeignItem, ForeignItemKind, Item, ItemKind, NodeId};
3131
use syntax::ast::{MetaItemKind, StmtKind, TraitItem, TraitItemKind, Variant};
3232
use syntax::ext::base::{MacroKind, SyntaxExtension};
33+
use syntax::ext::expand::AstFragment;
3334
use syntax::ext::hygiene::ExpnId;
3435
use syntax::feature_gate::is_builtin_attr;
3536
use syntax::parse::token::{self, Token};
@@ -67,7 +68,7 @@ impl<'a> ToNameBinding<'a> for (Res, ty::Visibility, Span, ExpnId) {
6768
}
6869
}
6970

70-
pub(crate) struct IsMacroExport;
71+
struct IsMacroExport;
7172

7273
impl<'a> ToNameBinding<'a> for (Res, ty::Visibility, Span, ExpnId, IsMacroExport) {
7374
fn to_name_binding(self, arenas: &'a ResolverArenas<'a>) -> &'a NameBinding<'a> {
@@ -84,7 +85,7 @@ impl<'a> ToNameBinding<'a> for (Res, ty::Visibility, Span, ExpnId, IsMacroExport
8485
impl<'a> Resolver<'a> {
8586
/// Defines `name` in namespace `ns` of module `parent` to be `def` if it is not yet defined;
8687
/// otherwise, reports an error.
87-
pub fn define<T>(&mut self, parent: Module<'a>, ident: Ident, ns: Namespace, def: T)
88+
crate fn define<T>(&mut self, parent: Module<'a>, ident: Ident, ns: Namespace, def: T)
8889
where T: ToNameBinding<'a>,
8990
{
9091
let binding = def.to_name_binding(self.arenas);
@@ -93,7 +94,7 @@ impl<'a> Resolver<'a> {
9394
}
9495
}
9596

96-
pub fn get_module(&mut self, def_id: DefId) -> Module<'a> {
97+
crate fn get_module(&mut self, def_id: DefId) -> Module<'a> {
9798
if def_id.krate == LOCAL_CRATE {
9899
return self.module_map[&def_id]
99100
}
@@ -119,7 +120,7 @@ impl<'a> Resolver<'a> {
119120
module
120121
}
121122

122-
pub fn macro_def_scope(&mut self, expn_id: ExpnId) -> Module<'a> {
123+
crate fn macro_def_scope(&mut self, expn_id: ExpnId) -> Module<'a> {
123124
let def_id = match self.macro_defs.get(&expn_id) {
124125
Some(def_id) => *def_id,
125126
None => return self.graph_root,
@@ -141,7 +142,7 @@ impl<'a> Resolver<'a> {
141142
}
142143
}
143144

144-
crate fn get_macro_by_def_id(&mut self, def_id: DefId) -> Option<Lrc<SyntaxExtension>> {
145+
fn get_macro_by_def_id(&mut self, def_id: DefId) -> Option<Lrc<SyntaxExtension>> {
145146
if let Some(ext) = self.macro_map.get(&def_id) {
146147
return Some(ext.clone());
147148
}
@@ -158,7 +159,7 @@ impl<'a> Resolver<'a> {
158159

159160
/// Ensures that the reduced graph rooted at the given external module
160161
/// is built, building it if it is not.
161-
pub fn populate_module_if_necessary(&mut self, module: Module<'a>) {
162+
crate fn populate_module_if_necessary(&mut self, module: Module<'a>) {
162163
if module.populated.get() { return }
163164
let def_id = module.def_id().unwrap();
164165
for child in self.cstore.item_children_untracked(def_id, self.session) {
@@ -168,11 +169,19 @@ impl<'a> Resolver<'a> {
168169
}
169170
module.populated.set(true)
170171
}
172+
173+
crate fn build_reduced_graph(
174+
&mut self, fragment: &AstFragment, parent_scope: ParentScope<'a>
175+
) -> LegacyScope<'a> {
176+
let mut visitor = BuildReducedGraphVisitor { r: self, parent_scope };
177+
fragment.visit_with(&mut visitor);
178+
visitor.parent_scope.legacy
179+
}
171180
}
172181

173-
pub struct BuildReducedGraphVisitor<'a, 'b> {
174-
pub r: &'b mut Resolver<'a>,
175-
pub parent_scope: ParentScope<'a>,
182+
struct BuildReducedGraphVisitor<'a, 'b> {
183+
r: &'b mut Resolver<'a>,
184+
parent_scope: ParentScope<'a>,
176185
}
177186

178187
impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {

src/librustc_resolve/diagnostics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ impl<'a> Resolver<'a> {
455455
let mut tmp_suggestions = Vec::new();
456456
add_module_candidates(prelude, &mut tmp_suggestions, filter_fn);
457457
suggestions.extend(tmp_suggestions.into_iter().filter(|s| {
458-
use_prelude || this.is_builtin_macro(s.res.opt_def_id())
458+
use_prelude || this.is_builtin_macro(s.res)
459459
}));
460460
}
461461
}

src/librustc_resolve/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,9 +1196,8 @@ impl<'a> Resolver<'a> {
11961196
f(self, MacroNS);
11971197
}
11981198

1199-
fn is_builtin_macro(&mut self, def_id: Option<DefId>) -> bool {
1200-
def_id.and_then(|def_id| self.get_macro_by_def_id(def_id))
1201-
.map_or(false, |ext| ext.is_builtin)
1199+
fn is_builtin_macro(&mut self, res: Res) -> bool {
1200+
self.get_macro(res).map_or(false, |ext| ext.is_builtin)
12021201
}
12031202

12041203
fn macro_def(&self, mut ctxt: SyntaxContext) -> DefId {

src/librustc_resolve/macros.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use crate::{CrateLint, Resolver, ResolutionError, Scope, ScopeSet, ParentScope,
33
use crate::{ModuleKind, NameBinding, PathResult, Segment, ToNameBinding};
44
use crate::{ModuleOrUniformRoot, KNOWN_TOOLS};
55
use crate::Namespace::*;
6-
use crate::build_reduced_graph::BuildReducedGraphVisitor;
76
use crate::resolve_imports::ImportResolver;
87
use rustc::hir::def::{self, DefKind, NonMacroAttrKind};
98
use rustc::hir::map::DefCollector;
@@ -131,9 +130,7 @@ impl<'a> base::Resolver for Resolver<'a> {
131130
// We are inside the `expansion` new, but other parent scope components are still the same.
132131
fragment.visit_with(&mut DefCollector::new(&mut self.definitions, expansion));
133132
let parent_scope = ParentScope { expansion, ..parent_scope };
134-
let mut visitor = BuildReducedGraphVisitor { r: self, parent_scope };
135-
fragment.visit_with(&mut visitor);
136-
let output_legacy_scope = visitor.parent_scope.legacy;
133+
let output_legacy_scope = self.build_reduced_graph(fragment, parent_scope);
137134
self.output_legacy_scopes.insert(expansion, output_legacy_scope);
138135
}
139136

@@ -530,7 +527,7 @@ impl<'a> Resolver<'a> {
530527
false,
531528
path_span,
532529
) {
533-
if use_prelude || this.is_builtin_macro(binding.res().opt_def_id()) {
530+
if use_prelude || this.is_builtin_macro(binding.res()) {
534531
result = Ok((binding, Flags::PRELUDE | Flags::MISC_FROM_PRELUDE));
535532
}
536533
}

0 commit comments

Comments
 (0)