]> git.lizzy.rs Git - rust.git/commitdiff
Handle tuples of length 1
authorGaëtan Cassiers <gaetan.cassiers@gmail.com>
Sat, 30 May 2015 14:52:46 +0000 (16:52 +0200)
committerGaëtan Cassiers <gaetan.cassiers@gmail.com>
Sat, 30 May 2015 14:52:46 +0000 (16:52 +0200)
src/expr.rs
tests/idem/tuple.rs

index ccc5017ea6032a841d551dbb24c9457902ecc07f..70695f30c4f01b6687dc15755440362279c940d8 100644 (file)
@@ -198,6 +198,10 @@ fn rewrite_tuple_lit(&mut self, items: &[ptr::P<ast::Expr>], width: usize, offse
         -> String {
         // opening paren
         let indent = offset + 1;
+        // In case of length 1, need a trailing comma
+        if items.len() == 1 {
+            return format!("({},)", self.rewrite_expr(&*items[0], width - 3, indent));
+        }
         // Only last line has width-1 as budget, other may take max_width
         let item_strs: Vec<_> =
             items.iter()
index ab2d9e6272c4e09aa7cf125aaad0a983263ac77b..3655cab0663048713d88011798da333101a61bac 100644 (file)
@@ -7,4 +7,5 @@ fn foo() {
                                   aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
                                   aaaaaaaaaaaaaaaaaaaaaaaaa,
                                   aaaa);
+    let a = (a,);
 }