Skip to content

Commit c46164b

Browse files
committed
Refactor away field vis of ModuleS
1 parent 1930483 commit c46164b

File tree

2 files changed

+27
-45
lines changed

2 files changed

+27
-45
lines changed

src/librustc_resolve/build_reduced_graph.rs

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ trait ToNameBinding<'a> {
4646
fn to_name_binding(self) -> NameBinding<'a>;
4747
}
4848

49-
impl<'a> ToNameBinding<'a> for (Module<'a>, Span) {
49+
impl<'a> ToNameBinding<'a> for (Module<'a>, Span, ty::Visibility) {
5050
fn to_name_binding(self) -> NameBinding<'a> {
51-
NameBinding::create_from_module(self.0, Some(self.1))
51+
NameBinding { kind: NameBindingKind::Module(self.0), span: Some(self.1), vis: self.2 }
5252
}
5353
}
5454

@@ -247,8 +247,8 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> {
247247
};
248248
let parent_link = ModuleParentLink(parent, name);
249249
let def = Def::Mod(def_id);
250-
let module = self.new_extern_crate_module(parent_link, def, vis, item.id);
251-
self.define(parent, name, TypeNS, (module, sp));
250+
let module = self.new_extern_crate_module(parent_link, def, item.id);
251+
self.define(parent, name, TypeNS, (module, sp, vis));
252252

253253
self.build_reduced_graph_for_external_crate(module);
254254
}
@@ -257,8 +257,8 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> {
257257
ItemMod(..) => {
258258
let parent_link = ModuleParentLink(parent, name);
259259
let def = Def::Mod(self.ast_map.local_def_id(item.id));
260-
let module = self.new_module(parent_link, Some(def), false, vis);
261-
self.define(parent, name, TypeNS, (module, sp));
260+
let module = self.new_module(parent_link, Some(def), false);
261+
self.define(parent, name, TypeNS, (module, sp, vis));
262262
self.module_map.insert(item.id, module);
263263
*parent_ref = module;
264264
}
@@ -289,12 +289,12 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> {
289289
ItemEnum(ref enum_definition, _) => {
290290
let parent_link = ModuleParentLink(parent, name);
291291
let def = Def::Enum(self.ast_map.local_def_id(item.id));
292-
let module = self.new_module(parent_link, Some(def), false, vis);
293-
self.define(parent, name, TypeNS, (module, sp));
292+
let module = self.new_module(parent_link, Some(def), false);
293+
self.define(parent, name, TypeNS, (module, sp, vis));
294294

295295
for variant in &(*enum_definition).variants {
296296
let item_def_id = self.ast_map.local_def_id(item.id);
297-
self.build_reduced_graph_for_variant(variant, item_def_id, module);
297+
self.build_reduced_graph_for_variant(variant, item_def_id, module, vis);
298298
}
299299
}
300300

@@ -328,8 +328,8 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> {
328328
// Add all the items within to a new module.
329329
let parent_link = ModuleParentLink(parent, name);
330330
let def = Def::Trait(def_id);
331-
let module_parent = self.new_module(parent_link, Some(def), false, vis);
332-
self.define(parent, name, TypeNS, (module_parent, sp));
331+
let module_parent = self.new_module(parent_link, Some(def), false);
332+
self.define(parent, name, TypeNS, (module_parent, sp, vis));
333333

334334
// Add the names of all the items to the trait info.
335335
for item in items {
@@ -353,7 +353,8 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> {
353353
fn build_reduced_graph_for_variant(&mut self,
354354
variant: &Variant,
355355
item_id: DefId,
356-
parent: Module<'b>) {
356+
parent: Module<'b>,
357+
vis: ty::Visibility) {
357358
let name = variant.node.name;
358359
if variant.node.data.is_struct() {
359360
// Not adding fields for variants as they are not accessed with a self receiver
@@ -364,8 +365,8 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> {
364365
// Variants are always treated as importable to allow them to be glob used.
365366
// All variants are defined in both type and value namespaces as future-proofing.
366367
let def = Def::Variant(item_id, self.ast_map.local_def_id(variant.node.data.id()));
367-
self.define(parent, name, ValueNS, (def, variant.span, parent.vis));
368-
self.define(parent, name, TypeNS, (def, variant.span, parent.vis));
368+
self.define(parent, name, ValueNS, (def, variant.span, vis));
369+
self.define(parent, name, TypeNS, (def, variant.span, vis));
369370
}
370371

371372
/// Constructs the reduced graph for one foreign item.
@@ -396,7 +397,7 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> {
396397
block_id);
397398

398399
let parent_link = BlockParentLink(parent, block_id);
399-
let new_module = self.new_module(parent_link, None, false, parent.vis);
400+
let new_module = self.new_module(parent_link, None, false);
400401
self.module_map.insert(block_id, new_module);
401402
*parent = new_module;
402403
}
@@ -425,8 +426,8 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> {
425426
debug!("(building reduced graph for external crate) building module {} {:?}",
426427
name, vis);
427428
let parent_link = ModuleParentLink(parent, name);
428-
let module = self.new_module(parent_link, Some(def), true, vis);
429-
self.try_define(parent, name, TypeNS, (module, DUMMY_SP));
429+
let module = self.new_module(parent_link, Some(def), true);
430+
self.try_define(parent, name, TypeNS, (module, DUMMY_SP, vis));
430431
}
431432
Def::Variant(_, variant_id) => {
432433
debug!("(building reduced graph for external crate) building variant {}", name);
@@ -467,8 +468,8 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> {
467468
}
468469

469470
let parent_link = ModuleParentLink(parent, name);
470-
let module = self.new_module(parent_link, Some(def), true, vis);
471-
self.try_define(parent, name, TypeNS, (module, DUMMY_SP));
471+
let module = self.new_module(parent_link, Some(def), true);
472+
self.try_define(parent, name, TypeNS, (module, DUMMY_SP, vis));
472473
}
473474
Def::TyAlias(..) | Def::AssociatedTy(..) => {
474475
debug!("(building reduced graph for external crate) building type {}", name);

src/librustc_resolve/lib.rs

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,6 @@ enum ParentLink<'a> {
818818
pub struct ModuleS<'a> {
819819
parent_link: ParentLink<'a>,
820820
def: Option<Def>,
821-
vis: ty::Visibility,
822821

823822
// If the module is an extern crate, `def` is root of the external crate and `extern_crate_id`
824823
// is the NodeId of the local `extern crate` item (otherwise, `extern_crate_id` is None).
@@ -849,12 +848,10 @@ impl<'a> ModuleS<'a> {
849848
fn new(parent_link: ParentLink<'a>,
850849
def: Option<Def>,
851850
external: bool,
852-
vis: ty::Visibility,
853851
arenas: &'a ResolverArenas<'a>) -> Self {
854852
ModuleS {
855853
parent_link: parent_link,
856854
def: def,
857-
vis: vis,
858855
extern_crate_id: None,
859856
resolutions: RefCell::new(HashMap::new()),
860857
unresolved_imports: RefCell::new(Vec::new()),
@@ -895,7 +892,7 @@ impl<'a> ModuleS<'a> {
895892

896893
impl<'a> fmt::Debug for ModuleS<'a> {
897894
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
898-
write!(f, "{:?}, {:?}", self.def, self.vis)
895+
write!(f, "{:?}", self.def)
899896
}
900897
}
901898

@@ -923,14 +920,6 @@ enum NameBindingKind<'a> {
923920
struct PrivacyError<'a>(Span, Name, &'a NameBinding<'a>);
924921

925922
impl<'a> NameBinding<'a> {
926-
fn create_from_module(module: Module<'a>, span: Option<Span>) -> Self {
927-
NameBinding {
928-
kind: NameBindingKind::Module(module),
929-
span: span,
930-
vis: module.vis,
931-
}
932-
}
933-
934923
fn module(&self) -> Option<Module<'a>> {
935924
match self.kind {
936925
NameBindingKind::Module(module) => Some(module),
@@ -1148,9 +1137,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
11481137
arenas: &'a ResolverArenas<'a>)
11491138
-> Resolver<'a, 'tcx> {
11501139
let root_def_id = ast_map.local_def_id(CRATE_NODE_ID);
1151-
let vis = ty::Visibility::Public;
11521140
let graph_root =
1153-
ModuleS::new(NoParentLink, Some(Def::Mod(root_def_id)), false, vis, arenas);
1141+
ModuleS::new(NoParentLink, Some(Def::Mod(root_def_id)), false, arenas);
11541142
let graph_root = arenas.alloc_module(graph_root);
11551143

11561144
Resolver {
@@ -1208,21 +1196,14 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
12081196
}
12091197
}
12101198

1211-
fn new_module(&self,
1212-
parent_link: ParentLink<'a>,
1213-
def: Option<Def>,
1214-
external: bool,
1215-
vis: ty::Visibility) -> Module<'a> {
1216-
self.arenas.alloc_module(ModuleS::new(parent_link, def, external, vis, self.arenas))
1199+
fn new_module(&self, parent_link: ParentLink<'a>, def: Option<Def>, external: bool)
1200+
-> Module<'a> {
1201+
self.arenas.alloc_module(ModuleS::new(parent_link, def, external, self.arenas))
12171202
}
12181203

1219-
fn new_extern_crate_module(&self,
1220-
parent_link: ParentLink<'a>,
1221-
def: Def,
1222-
vis: ty::Visibility,
1223-
local_node_id: NodeId)
1204+
fn new_extern_crate_module(&self, parent_link: ParentLink<'a>, def: Def, local_node_id: NodeId)
12241205
-> Module<'a> {
1225-
let mut module = ModuleS::new(parent_link, Some(def), false, vis, self.arenas);
1206+
let mut module = ModuleS::new(parent_link, Some(def), false, self.arenas);
12261207
module.extern_crate_id = Some(local_node_id);
12271208
self.arenas.modules.alloc(module)
12281209
}

0 commit comments

Comments
 (0)