about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorKevin Mehall <km@kevinmehall.net>2014-10-27 00:11:26 -0700
committerKevin Mehall <km@kevinmehall.net>2014-10-27 00:35:35 -0700
commite5f709079a2f9c5227e10f5f4cd0371a2fd76ae3 (patch)
treea60a4c92c4f9b906cb74846b79b17bafad7f2a7a /src/libsyntax
parentf037452447f5f46deb26e1c483fe88fb51a19198 (diff)
downloadrust-e5f709079a2f9c5227e10f5f4cd0371a2fd76ae3.tar.gz
rust-e5f709079a2f9c5227e10f5f4cd0371a2fd76ae3.zip
Preserve struct field pattern shorthand in the prettyprinter.
Use the `is_shorthand` field introduced by #17813 (ead6c4b) to make the
prettyprinter output the shorthand form. Fixes a few places that set
`is_shorthand: true` when the pattern is not a PatIdent with the same
name as the field.
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/ext/deriving/generic/mod.rs2
-rw-r--r--src/libsyntax/print/pprust.rs6
2 files changed, 5 insertions, 3 deletions
diff --git a/src/libsyntax/ext/deriving/generic/mod.rs b/src/libsyntax/ext/deriving/generic/mod.rs
index 533a28998bd..7c32b845508 100644
--- a/src/libsyntax/ext/deriving/generic/mod.rs
+++ b/src/libsyntax/ext/deriving/generic/mod.rs
@@ -1250,7 +1250,7 @@ impl<'a> TraitDef<'a> {
                 // id is guaranteed to be Some
                 codemap::Spanned {
                     span: pat.span,
-                    node: ast::FieldPat { ident: id.unwrap(), pat: pat, is_shorthand: true },
+                    node: ast::FieldPat { ident: id.unwrap(), pat: pat, is_shorthand: false },
                 }
             }).collect();
             cx.pat_struct(self.span, matching_path, field_pats)
diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs
index b63f9b0120b..ed4a16da013 100644
--- a/src/libsyntax/print/pprust.rs
+++ b/src/libsyntax/print/pprust.rs
@@ -1983,8 +1983,10 @@ impl<'a> State<'a> {
                     Consistent, fields.as_slice(),
                     |s, f| {
                         try!(s.cbox(indent_unit));
-                        try!(s.print_ident(f.node.ident));
-                        try!(s.word_nbsp(":"));
+                        if !f.node.is_shorthand {
+                            try!(s.print_ident(f.node.ident));
+                            try!(s.word_nbsp(":"));
+                        }
                         try!(s.print_pat(&*f.node.pat));
                         s.end()
                     },