]> git.lizzy.rs Git - rust.git/commitdiff
Refactor away field `vis` of `ModuleS`
authorJeffrey Seyfried <jeffrey.seyfried@gmail.com>
Tue, 26 Apr 2016 04:20:50 +0000 (04:20 +0000)
committerJeffrey Seyfried <jeffrey.seyfried@gmail.com>
Tue, 26 Apr 2016 09:01:24 +0000 (09:01 +0000)
src/librustc_resolve/build_reduced_graph.rs
src/librustc_resolve/lib.rs

index ed473da19176b3c1378eff1301c705b7f5335ad4..6dfd3e00be86463aae79a6199a53ad318a348360 100644 (file)
@@ -46,9 +46,9 @@ trait ToNameBinding<'a> {
     fn to_name_binding(self) -> NameBinding<'a>;
 }
 
-impl<'a> ToNameBinding<'a> for (Module<'a>, Span) {
+impl<'a> ToNameBinding<'a> for (Module<'a>, Span, ty::Visibility) {
     fn to_name_binding(self) -> NameBinding<'a> {
-        NameBinding::create_from_module(self.0, Some(self.1))
+        NameBinding { kind: NameBindingKind::Module(self.0), span: Some(self.1), vis: self.2 }
     }
 }
 
@@ -247,8 +247,8 @@ fn build_reduced_graph_for_item(&mut self, item: &Item, parent_ref: &mut Module<
                     };
                     let parent_link = ModuleParentLink(parent, name);
                     let def = Def::Mod(def_id);
-                    let module = self.new_extern_crate_module(parent_link, def, vis, item.id);
-                    self.define(parent, name, TypeNS, (module, sp));
+                    let module = self.new_extern_crate_module(parent_link, def, item.id);
+                    self.define(parent, name, TypeNS, (module, sp, vis));
 
                     self.build_reduced_graph_for_external_crate(module);
                 }
@@ -257,8 +257,8 @@ fn build_reduced_graph_for_item(&mut self, item: &Item, parent_ref: &mut Module<
             ItemMod(..) => {
                 let parent_link = ModuleParentLink(parent, name);
                 let def = Def::Mod(self.ast_map.local_def_id(item.id));
-                let module = self.new_module(parent_link, Some(def), false, vis);
-                self.define(parent, name, TypeNS, (module, sp));
+                let module = self.new_module(parent_link, Some(def), false);
+                self.define(parent, name, TypeNS, (module, sp, vis));
                 self.module_map.insert(item.id, module);
                 *parent_ref = module;
             }
@@ -289,12 +289,12 @@ fn build_reduced_graph_for_item(&mut self, item: &Item, parent_ref: &mut Module<
             ItemEnum(ref enum_definition, _) => {
                 let parent_link = ModuleParentLink(parent, name);
                 let def = Def::Enum(self.ast_map.local_def_id(item.id));
-                let module = self.new_module(parent_link, Some(def), false, vis);
-                self.define(parent, name, TypeNS, (module, sp));
+                let module = self.new_module(parent_link, Some(def), false);
+                self.define(parent, name, TypeNS, (module, sp, vis));
 
                 for variant in &(*enum_definition).variants {
                     let item_def_id = self.ast_map.local_def_id(item.id);
-                    self.build_reduced_graph_for_variant(variant, item_def_id, module);
+                    self.build_reduced_graph_for_variant(variant, item_def_id, module, vis);
                 }
             }
 
@@ -328,8 +328,8 @@ fn build_reduced_graph_for_item(&mut self, item: &Item, parent_ref: &mut Module<
                 // Add all the items within to a new module.
                 let parent_link = ModuleParentLink(parent, name);
                 let def = Def::Trait(def_id);
-                let module_parent = self.new_module(parent_link, Some(def), false, vis);
-                self.define(parent, name, TypeNS, (module_parent, sp));
+                let module_parent = self.new_module(parent_link, Some(def), false);
+                self.define(parent, name, TypeNS, (module_parent, sp, vis));
 
                 // Add the names of all the items to the trait info.
                 for item in items {
@@ -353,7 +353,8 @@ fn build_reduced_graph_for_item(&mut self, item: &Item, parent_ref: &mut Module<
     fn build_reduced_graph_for_variant(&mut self,
                                        variant: &Variant,
                                        item_id: DefId,
-                                       parent: Module<'b>) {
+                                       parent: Module<'b>,
+                                       vis: ty::Visibility) {
         let name = variant.node.name;
         if variant.node.data.is_struct() {
             // Not adding fields for variants as they are not accessed with a self receiver
@@ -364,8 +365,8 @@ fn build_reduced_graph_for_variant(&mut self,
         // Variants are always treated as importable to allow them to be glob used.
         // All variants are defined in both type and value namespaces as future-proofing.
         let def = Def::Variant(item_id, self.ast_map.local_def_id(variant.node.data.id()));
-        self.define(parent, name, ValueNS, (def, variant.span, parent.vis));
-        self.define(parent, name, TypeNS, (def, variant.span, parent.vis));
+        self.define(parent, name, ValueNS, (def, variant.span, vis));
+        self.define(parent, name, TypeNS, (def, variant.span, vis));
     }
 
     /// Constructs the reduced graph for one foreign item.
@@ -396,7 +397,7 @@ fn build_reduced_graph_for_block(&mut self, block: &Block, parent: &mut Module<'
                    block_id);
 
             let parent_link = BlockParentLink(parent, block_id);
-            let new_module = self.new_module(parent_link, None, false, parent.vis);
+            let new_module = self.new_module(parent_link, None, false);
             self.module_map.insert(block_id, new_module);
             *parent = new_module;
         }
@@ -425,8 +426,8 @@ fn build_reduced_graph_for_external_crate_def(&mut self, parent: Module<'b>, xcd
                 debug!("(building reduced graph for external crate) building module {} {:?}",
                        name, vis);
                 let parent_link = ModuleParentLink(parent, name);
-                let module = self.new_module(parent_link, Some(def), true, vis);
-                self.try_define(parent, name, TypeNS, (module, DUMMY_SP));
+                let module = self.new_module(parent_link, Some(def), true);
+                self.try_define(parent, name, TypeNS, (module, DUMMY_SP, vis));
             }
             Def::Variant(_, variant_id) => {
                 debug!("(building reduced graph for external crate) building variant {}", name);
@@ -467,8 +468,8 @@ fn build_reduced_graph_for_external_crate_def(&mut self, parent: Module<'b>, xcd
                 }
 
                 let parent_link = ModuleParentLink(parent, name);
-                let module = self.new_module(parent_link, Some(def), true, vis);
-                self.try_define(parent, name, TypeNS, (module, DUMMY_SP));
+                let module = self.new_module(parent_link, Some(def), true);
+                self.try_define(parent, name, TypeNS, (module, DUMMY_SP, vis));
             }
             Def::TyAlias(..) | Def::AssociatedTy(..) => {
                 debug!("(building reduced graph for external crate) building type {}", name);
index 293b4de71fac403cb809136d93aaddd00b082149..16954f6bc97b4226c83c4b71716496e5f31774e0 100644 (file)
@@ -818,7 +818,6 @@ enum ParentLink<'a> {
 pub struct ModuleS<'a> {
     parent_link: ParentLink<'a>,
     def: Option<Def>,
-    vis: ty::Visibility,
 
     // If the module is an extern crate, `def` is root of the external crate and `extern_crate_id`
     // is the NodeId of the local `extern crate` item (otherwise, `extern_crate_id` is None).
@@ -849,12 +848,10 @@ impl<'a> ModuleS<'a> {
     fn new(parent_link: ParentLink<'a>,
            def: Option<Def>,
            external: bool,
-           vis: ty::Visibility,
            arenas: &'a ResolverArenas<'a>) -> Self {
         ModuleS {
             parent_link: parent_link,
             def: def,
-            vis: vis,
             extern_crate_id: None,
             resolutions: RefCell::new(HashMap::new()),
             unresolved_imports: RefCell::new(Vec::new()),
@@ -895,7 +892,7 @@ fn is_trait(&self) -> bool {
 
 impl<'a> fmt::Debug for ModuleS<'a> {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        write!(f, "{:?}, {:?}", self.def, self.vis)
+        write!(f, "{:?}", self.def)
     }
 }
 
@@ -923,14 +920,6 @@ enum NameBindingKind<'a> {
 struct PrivacyError<'a>(Span, Name, &'a NameBinding<'a>);
 
 impl<'a> NameBinding<'a> {
-    fn create_from_module(module: Module<'a>, span: Option<Span>) -> Self {
-        NameBinding {
-            kind: NameBindingKind::Module(module),
-            span: span,
-            vis: module.vis,
-        }
-    }
-
     fn module(&self) -> Option<Module<'a>> {
         match self.kind {
             NameBindingKind::Module(module) => Some(module),
@@ -1148,9 +1137,8 @@ fn new(session: &'a Session,
            arenas: &'a ResolverArenas<'a>)
            -> Resolver<'a, 'tcx> {
         let root_def_id = ast_map.local_def_id(CRATE_NODE_ID);
-        let vis = ty::Visibility::Public;
         let graph_root =
-            ModuleS::new(NoParentLink, Some(Def::Mod(root_def_id)), false, vis, arenas);
+            ModuleS::new(NoParentLink, Some(Def::Mod(root_def_id)), false, arenas);
         let graph_root = arenas.alloc_module(graph_root);
 
         Resolver {
@@ -1208,21 +1196,14 @@ fn arenas() -> ResolverArenas<'a> {
         }
     }
 
-    fn new_module(&self,
-                  parent_link: ParentLink<'a>,
-                  def: Option<Def>,
-                  external: bool,
-                  vis: ty::Visibility) -> Module<'a> {
-        self.arenas.alloc_module(ModuleS::new(parent_link, def, external, vis, self.arenas))
+    fn new_module(&self, parent_link: ParentLink<'a>, def: Option<Def>, external: bool)
+                  -> Module<'a> {
+        self.arenas.alloc_module(ModuleS::new(parent_link, def, external, self.arenas))
     }
 
-    fn new_extern_crate_module(&self,
-                               parent_link: ParentLink<'a>,
-                               def: Def,
-                               vis: ty::Visibility,
-                               local_node_id: NodeId)
+    fn new_extern_crate_module(&self, parent_link: ParentLink<'a>, def: Def, local_node_id: NodeId)
                                -> Module<'a> {
-        let mut module = ModuleS::new(parent_link, Some(def), false, vis, self.arenas);
+        let mut module = ModuleS::new(parent_link, Some(def), false, self.arenas);
         module.extern_crate_id = Some(local_node_id);
         self.arenas.modules.alloc(module)
     }