This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +12
-7
lines changed
compiler/rustc_ast_pretty/src Expand file tree Collapse file tree 2 files changed +12
-7
lines changed Original file line number Diff line number Diff line change @@ -288,12 +288,11 @@ impl Printer {
288
288
self . left_total = 1 ;
289
289
self . right_total = 1 ;
290
290
self . right = self . left ;
291
- self . buf . truncate ( 1 ) ;
291
+ self . buf . clear ( ) ;
292
292
} else {
293
293
self . right += 1 ;
294
- self . buf . advance_right ( ) ;
295
294
}
296
- self . buf [ self . right ] = BufEntry { token : Token :: Begin ( b) , size : -self . right_total } ;
295
+ self . buf . push ( BufEntry { token : Token :: Begin ( b) , size : -self . right_total } ) ;
297
296
self . scan_stack . push_front ( self . right ) ;
298
297
}
299
298
@@ -302,8 +301,7 @@ impl Printer {
302
301
self . print_end ( ) ;
303
302
} else {
304
303
self . right += 1 ;
305
- self . buf . advance_right ( ) ;
306
- self . buf [ self . right ] = BufEntry { token : Token :: End , size : -1 } ;
304
+ self . buf . push ( BufEntry { token : Token :: End , size : -1 } ) ;
307
305
self . scan_stack . push_front ( self . right ) ;
308
306
}
309
307
}
@@ -329,9 +327,8 @@ impl Printer {
329
327
self . print_string ( s) ;
330
328
} else {
331
329
self . right += 1 ;
332
- self . buf . advance_right ( ) ;
333
330
let len = s. len ( ) as isize ;
334
- self . buf [ self . right ] = BufEntry { token : Token :: String ( s) , size : len } ;
331
+ self . buf . push ( BufEntry { token : Token :: String ( s) , size : len } ) ;
335
332
self . right_total += len;
336
333
self . check_stream ( ) ;
337
334
}
Original file line number Diff line number Diff line change @@ -22,6 +22,10 @@ impl<T> RingBuffer<T> {
22
22
RingBuffer { data : VecDeque :: new ( ) , offset : 0 }
23
23
}
24
24
25
+ pub fn push ( & mut self , value : T ) {
26
+ self . data . push_back ( value) ;
27
+ }
28
+
25
29
pub fn advance_right ( & mut self )
26
30
where
27
31
T : Default ,
@@ -34,6 +38,10 @@ impl<T> RingBuffer<T> {
34
38
self . offset += 1 ;
35
39
}
36
40
41
+ pub fn clear ( & mut self ) {
42
+ self . data . clear ( ) ;
43
+ }
44
+
37
45
pub fn truncate ( & mut self , len : usize ) {
38
46
self . data . truncate ( len) ;
39
47
}
You can’t perform that action at this time.
0 commit comments