File tree Expand file tree Collapse file tree 2 files changed +27
-7
lines changed
compiler/rustc_ast_pretty/src Expand file tree Collapse file tree 2 files changed +27
-7
lines changed Original file line number Diff line number Diff line change @@ -148,7 +148,7 @@ pub enum Breaks {
148
148
Inconsistent ,
149
149
}
150
150
151
- #[ derive( Clone , Copy ) ]
151
+ #[ derive( Clone , Copy , PartialEq ) ]
152
152
enum IndentStyle {
153
153
/// Vertically aligned under whatever column this block begins at.
154
154
///
@@ -164,19 +164,20 @@ enum IndentStyle {
164
164
Block { offset : isize } ,
165
165
}
166
166
167
- #[ derive( Clone , Copy ) ]
167
+ #[ derive( Clone , Copy , Default , PartialEq ) ]
168
168
pub struct BreakToken {
169
169
offset : isize ,
170
170
blank_space : isize ,
171
+ pre_break : Option < char > ,
171
172
}
172
173
173
- #[ derive( Clone , Copy ) ]
174
+ #[ derive( Clone , Copy , PartialEq ) ]
174
175
pub struct BeginToken {
175
176
indent : IndentStyle ,
176
177
breaks : Breaks ,
177
178
}
178
179
179
- #[ derive( Clone ) ]
180
+ #[ derive( Clone , PartialEq ) ]
180
181
pub enum Token {
181
182
// In practice a string token contains either a `&'static str` or a
182
183
// `String`. `Cow` is overkill for this because we never modify the data,
@@ -415,6 +416,9 @@ impl Printer {
415
416
self . pending_indentation += token. blank_space ;
416
417
self . space -= token. blank_space ;
417
418
} else {
419
+ if let Some ( pre_break) = token. pre_break {
420
+ self . out . push ( pre_break) ;
421
+ }
418
422
self . out . push ( '\n' ) ;
419
423
let indent = self . indent as isize + token. offset ;
420
424
self . pending_indentation = indent;
Original file line number Diff line number Diff line change @@ -25,7 +25,11 @@ impl Printer {
25
25
}
26
26
27
27
pub fn break_offset ( & mut self , n : usize , off : isize ) {
28
- self . scan_break ( BreakToken { offset : off, blank_space : n as isize } )
28
+ self . scan_break ( BreakToken {
29
+ offset : off,
30
+ blank_space : n as isize ,
31
+ ..BreakToken :: default ( )
32
+ } ) ;
29
33
}
30
34
31
35
pub fn end ( & mut self ) {
@@ -66,12 +70,24 @@ impl Printer {
66
70
}
67
71
68
72
pub fn hardbreak_tok_offset ( off : isize ) -> Token {
69
- Token :: Break ( BreakToken { offset : off, blank_space : SIZE_INFINITY } )
73
+ Token :: Break ( BreakToken {
74
+ offset : off,
75
+ blank_space : SIZE_INFINITY ,
76
+ ..BreakToken :: default ( )
77
+ } )
78
+ }
79
+
80
+ pub fn trailing_comma ( & mut self ) {
81
+ self . scan_break ( BreakToken {
82
+ blank_space : 1 ,
83
+ pre_break : Some ( ',' ) ,
84
+ ..BreakToken :: default ( )
85
+ } ) ;
70
86
}
71
87
}
72
88
73
89
impl Token {
74
90
pub fn is_hardbreak_tok ( & self ) -> bool {
75
- matches ! ( self , Token :: Break ( BreakToken { offset : 0 , blank_space : SIZE_INFINITY } ) )
91
+ * self == Printer :: hardbreak_tok_offset ( 0 )
76
92
}
77
93
}
You can’t perform that action at this time.
0 commit comments