diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2015-10-08 23:45:46 +0300 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2015-10-13 15:19:25 +0300 |
| commit | 40aa09e4c9f4c3f0fa2b088895c8f5125325eaa4 (patch) | |
| tree | 0ea29987683fbd21b30e2bc23769517a7984a116 /src/libsyntax/print | |
| parent | 30af54dede8b9f03a83dd5ad588bb430a5a76270 (diff) | |
| download | rust-40aa09e4c9f4c3f0fa2b088895c8f5125325eaa4.tar.gz rust-40aa09e4c9f4c3f0fa2b088895c8f5125325eaa4.zip | |
Merge struct fields and struct kind
Diffstat (limited to 'src/libsyntax/print')
| -rw-r--r-- | src/libsyntax/print/pprust.rs | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 0f6041d2cd0..161f6243f85 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -520,6 +520,18 @@ pub trait PrintState<'a> { self.end() } + fn commasep_iter<'it, T: 'it, F, I>(&mut self, b: Breaks, elts: I, mut op: F) -> io::Result<()> + where F: FnMut(&mut Self, &T) -> io::Result<()>, + I: Iterator<Item=&'it T>, + { + try!(self.rbox(0, b)); + let mut first = true; + for elt in elts { + if first { first = false; } else { try!(self.word_space(",")); } + try!(op(self, elt)); + } + self.end() + } fn next_lit(&mut self, pos: BytePos) -> Option<comments::Literal> { let mut cur_lit = self.cur_cmnt_and_lit().cur_lit; @@ -1392,11 +1404,11 @@ impl<'a> State<'a> { print_finalizer: bool) -> io::Result<()> { try!(self.print_ident(ident)); try!(self.print_generics(generics)); - if struct_def.kind != ast::VariantKind::Struct { - if struct_def.kind == ast::VariantKind::Tuple { + if !struct_def.is_struct() { + if struct_def.is_tuple() { try!(self.popen()); - try!(self.commasep( - Inconsistent, &struct_def.fields, + try!(self.commasep_iter( + Inconsistent, struct_def.fields(), |s, field| { match field.node.kind { ast::NamedField(..) => panic!("unexpected named field"), @@ -1422,7 +1434,7 @@ impl<'a> State<'a> { try!(self.bopen()); try!(self.hardbreak_if_not_bol()); - for field in &struct_def.fields { + for field in struct_def.fields() { match field.node.kind { ast::UnnamedField(..) => panic!("unexpected unnamed field"), ast::NamedField(ident, visibility) => { @@ -3119,9 +3131,8 @@ mod tests { name: ident, attrs: Vec::new(), // making this up as I go.... ? - data: P(ast::VariantData { fields: Vec::new(), - id: ast::DUMMY_NODE_ID, - kind: ast::VariantKind::Unit }), + data: P(ast::VariantData { data_: ast::VariantData_::Unit, + id: ast::DUMMY_NODE_ID}), disr_expr: None, }); |
