save-analysis: only emit public fields in value of a struct if the config permits

This commit is contained in:
Nick Cameron 2017-08-02 15:46:59 +12:00
parent 640cfc852a
commit 4e6c1dddff

View File

@ -560,14 +560,20 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
let (value, fields) =
if let ast::ItemKind::Struct(ast::VariantData::Struct(ref fields, _), _) = item.node
{
let include_priv_fields = !self.save_ctxt.config.pub_only;
let fields_str = fields.iter()
.enumerate()
.map(|(i, f)| f.ident.map(|i| i.to_string())
.unwrap_or(i.to_string()))
.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(", ");
(format!("{} {{ {} }}", name, fields_str),
fields.iter().map(|f| ::id_from_node_id(f.id, &self.save_ctxt)).collect())
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![])
};