]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_save_analysis/dump_visitor.rs
Appease tidy and fix save-analysis config for dist builds
[rust.git] / src / librustc_save_analysis / dump_visitor.rs
index ebdd99dc80258ae8c108887289962e49d333bde6..4740f9a0d5a59662808fc170494908df69e565a2 100644 (file)
@@ -29,6 +29,7 @@
 use rustc::hir::map::Node;
 use rustc::session::Session;
 use rustc::ty::{self, TyCtxt};
+use rustc_data_structures::fx::FxHashSet;
 
 use std::path::Path;
 
@@ -74,6 +75,7 @@ pub struct DumpVisitor<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> {
     // we only write one macro def per unique macro definition, and
     // one macro use per unique callsite span.
     // mac_defs: HashSet<Span>,
+    macro_calls: FxHashSet<Span>,
 }
 
 impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
@@ -89,6 +91,7 @@ pub fn new(save_ctxt: SaveContext<'l, 'tcx>,
             span: span_utils.clone(),
             cur_scope: CRATE_NODE_ID,
             // mac_defs: HashSet::new(),
+            macro_calls: FxHashSet(),
         }
     }
 
@@ -557,14 +560,21 @@ fn process_struct(&mut self,
         let (value, fields) =
             if let ast::ItemKind::Struct(ast::VariantData::Struct(ref fields, _), _) = item.node
         {
-            let fields_str = fields.iter()
-                                   .enumerate()
-                                   .map(|(i, f)| f.ident.map(|i| i.to_string())
-                                                  .unwrap_or(i.to_string()))
-                                   .collect::<Vec<_>>()
-                                   .join(", ");
-            (format!("{} {{ {} }}", name, fields_str),
-             fields.iter().map(|f| ::id_from_node_id(f.id, &self.save_ctxt)).collect())
+            let include_priv_fields = !self.save_ctxt.config.pub_only;
+            let fields_str = fields
+                .iter()
+                .enumerate()
+                .filter_map(|(i, f)| {
+                     if include_priv_fields || f.vis == ast::Visibility::Public {
+                         f.ident.map(|i| i.to_string()).or_else(|| Some(i.to_string()))
+                     } else {
+                         None
+                     }
+                })
+                .collect::<Vec<_>>()
+                .join(", ");
+            let value = format!("{} {{ {} }}", name, fields_str);
+            (value, fields.iter().map(|f| ::id_from_node_id(f.id, &self.save_ctxt)).collect())
         } else {
             (String::new(), vec![])
         };
@@ -972,11 +982,19 @@ fn process_var_decl(&mut self, p: &'l ast::Pat, value: String) {
     /// callsite spans to record macro definition and use data, using the
     /// mac_uses and mac_defs sets to prevent multiples.
     fn process_macro_use(&mut self, span: Span) {
+        let source_span = span.source_callsite();
+        if self.macro_calls.contains(&source_span) {
+            return;
+        }
+        self.macro_calls.insert(source_span);
+
         let data = match self.save_ctxt.get_macro_use_data(span) {
             None => return,
             Some(data) => data,
         };
 
+        self.dumper.macro_use(data);
+
         // FIXME write the macro def
         // let mut hasher = DefaultHasher::new();
         // data.callee_span.hash(&mut hasher);
@@ -996,7 +1014,6 @@ fn process_macro_use(&mut self, span: Span) {
         //         }.lower(self.tcx));
         //     }
         // }
-        self.dumper.macro_use(data);
     }
 
     fn process_trait_item(&mut self, trait_item: &'l ast::TraitItem, trait_id: DefId) {