]> git.lizzy.rs Git - rust.git/blobdiff - src/libsyntax/print/pprust.rs
Merge VariantData and VariantData_
[rust.git] / src / libsyntax / print / pprust.rs
index 5535064c8eca29e62ee83b75aa3a8c29ecdee175..e5a9ce216a92ab5ff1ebe8f76c7d9ab76a7c03dd 100644 (file)
@@ -520,6 +520,18 @@ fn commasep<T, F>(&mut self, b: Breaks, elts: &[T], mut op: F) -> io::Result<()>
         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;
@@ -1385,18 +1397,18 @@ pub fn print_visibility(&mut self, vis: ast::Visibility) -> io::Result<()> {
     }
 
     pub fn print_struct(&mut self,
-                        struct_def: &ast::StructDef,
+                        struct_def: &ast::VariantData,
                         generics: &ast::Generics,
                         ident: ast::Ident,
                         span: codemap::Span,
                         print_finalizer: bool) -> io::Result<()> {
         try!(self.print_ident(ident));
         try!(self.print_generics(generics));
-        if struct_def.kind != ast::VariantKind::Dict {
-            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 @@ pub fn print_struct(&mut self,
             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) => {
@@ -1510,7 +1522,7 @@ pub fn print_tts(&mut self, tts: &[ast::TokenTree]) -> io::Result<()> {
     pub fn print_variant(&mut self, v: &ast::Variant) -> io::Result<()> {
         try!(self.head(""));
         let generics = ast_util::empty_generics();
-        try!(self.print_struct(&v.node.def, &generics, v.node.name, v.span, false));
+        try!(self.print_struct(&v.node.data, &generics, v.node.name, v.span, false));
         match v.node.disr_expr {
             Some(ref d) => {
                 try!(space(&mut self.s));
@@ -3119,9 +3131,7 @@ fn test_variant_to_string() {
             name: ident,
             attrs: Vec::new(),
             // making this up as I go.... ?
-            def: P(ast::StructDef { fields: Vec::new(),
-                                    id: ast::DUMMY_NODE_ID,
-                                    kind: ast::VariantKind::Unit }),
+            data: P(ast::VariantData::Unit(ast::DUMMY_NODE_ID)),
             disr_expr: None,
         });