File tree Expand file tree Collapse file tree 3 files changed +21
-3
lines changed Expand file tree Collapse file tree 3 files changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ pub enum Breaks {
16
16
pub struct BreakToken {
17
17
pub offset : isize ,
18
18
pub blank_space : usize ,
19
+ pub trailing_comma : bool ,
19
20
}
20
21
21
22
#[ derive( Clone , Copy ) ]
@@ -255,6 +256,9 @@ impl Printer {
255
256
self . pending_indentation += token. blank_space ;
256
257
self . space -= token. blank_space as isize ;
257
258
} else {
259
+ if token. trailing_comma {
260
+ self . out . push ( ',' ) ;
261
+ }
258
262
self . out . push ( '\n' ) ;
259
263
let indent = self . indent as isize + token. offset ;
260
264
self . pending_indentation = indent as usize ;
Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ impl Printer {
26
26
self . scan_break ( BreakToken {
27
27
offset : off,
28
28
blank_space : n,
29
+ trailing_comma : false ,
29
30
} ) ;
30
31
}
31
32
@@ -62,6 +63,15 @@ impl Printer {
62
63
Token :: Break ( BreakToken {
63
64
offset : off,
64
65
blank_space : algorithm:: SIZE_INFINITY as usize ,
66
+ trailing_comma : false ,
65
67
} )
66
68
}
69
+
70
+ pub fn trailing_comma ( & mut self ) {
71
+ self . scan_break ( BreakToken {
72
+ offset : 0 ,
73
+ blank_space : 0 ,
74
+ trailing_comma : true ,
75
+ } ) ;
76
+ }
67
77
}
Original file line number Diff line number Diff line change @@ -47,10 +47,14 @@ impl Printer {
47
47
self . word ( "(" ) ;
48
48
self . cbox ( INDENT ) ;
49
49
self . zerobreak ( ) ;
50
- for field in & fields. unnamed {
50
+ for ( i , field) in fields. unnamed . iter ( ) . enumerate ( ) {
51
51
self . field ( field) ;
52
- self . word ( "," ) ;
53
- self . space ( ) ;
52
+ if i < fields. unnamed . len ( ) - 1 {
53
+ self . word ( "," ) ;
54
+ self . space ( ) ;
55
+ } else {
56
+ self . trailing_comma ( ) ;
57
+ }
54
58
}
55
59
self . offset ( -INDENT ) ;
56
60
self . end ( ) ;
You can’t perform that action at this time.
0 commit comments