@@ -58,6 +58,10 @@ pub struct FmtVisitor<'a> {
58
58
}
59
59
60
60
impl < ' a > FmtVisitor < ' a > {
61
+ pub fn shape ( & self ) -> Shape {
62
+ Shape :: indented ( self . block_indent , self . config )
63
+ }
64
+
61
65
fn visit_stmt ( & mut self , stmt : & ast:: Stmt ) {
62
66
debug ! (
63
67
"visit_stmt: {:?} {:?}" ,
@@ -138,9 +142,7 @@ impl<'a> FmtVisitor<'a> {
138
142
if let Some ( first_stmt) = b. stmts . first ( ) {
139
143
let attr_lo = inner_attrs
140
144
. and_then ( |attrs| {
141
- utils:: inner_attributes ( attrs)
142
- . first ( )
143
- . map ( |attr| attr. span . lo )
145
+ inner_attributes ( attrs) . first ( ) . map ( |attr| attr. span . lo )
144
146
} )
145
147
. or_else ( || {
146
148
// Attributes for an item in a statement position
@@ -218,7 +220,7 @@ impl<'a> FmtVisitor<'a> {
218
220
let mut unindent_comment = self . is_if_else_block && !b. stmts . is_empty ( ) ;
219
221
if unindent_comment {
220
222
let end_pos = source ! ( self , b. span) . hi - brace_compensation - remove_len;
221
- let snippet = self . get_context ( ) . snippet ( mk_sp ( self . last_pos , end_pos) ) ;
223
+ let snippet = self . snippet ( mk_sp ( self . last_pos , end_pos) ) ;
222
224
unindent_comment = snippet. contains ( "//" ) || snippet. contains ( "/*" ) ;
223
225
}
224
226
// FIXME: we should compress any newlines here to just one
@@ -336,7 +338,7 @@ impl<'a> FmtVisitor<'a> {
336
338
self . push_rewrite ( item. span , None ) ;
337
339
return ;
338
340
}
339
- } else if utils :: contains_skip ( & item. attrs ) {
341
+ } else if contains_skip ( & item. attrs ) {
340
342
// Module is not inline, but should be skipped.
341
343
return ;
342
344
} else {
@@ -371,7 +373,7 @@ impl<'a> FmtVisitor<'a> {
371
373
}
372
374
ast:: ItemKind :: Impl ( ..) => {
373
375
self . format_missing_with_indent ( source ! ( self , item. span) . lo ) ;
374
- let snippet = self . get_context ( ) . snippet ( item. span ) ;
376
+ let snippet = self . snippet ( item. span ) ;
375
377
let where_span_end = snippet
376
378
. find_uncommented ( "{" )
377
379
. map ( |x| ( BytePos ( x as u32 ) ) + source ! ( self , item. span) . lo ) ;
@@ -635,9 +637,7 @@ impl<'a> FmtVisitor<'a> {
635
637
skip_out_of_file_lines_range_visitor ! ( self , mac. span) ;
636
638
637
639
// 1 = ;
638
- let shape = Shape :: indented ( self . block_indent , self . config )
639
- . sub_width ( 1 )
640
- . unwrap ( ) ;
640
+ let shape = self . shape ( ) . sub_width ( 1 ) . unwrap ( ) ;
641
641
let rewrite = rewrite_macro ( mac, ident, & self . get_context ( ) , shape, pos) ;
642
642
self . push_rewrite ( mac. span , rewrite) ;
643
643
}
@@ -677,7 +677,7 @@ impl<'a> FmtVisitor<'a> {
677
677
678
678
// Returns true if we should skip the following item.
679
679
pub fn visit_attrs ( & mut self , attrs : & [ ast:: Attribute ] , style : ast:: AttrStyle ) -> bool {
680
- if utils :: contains_skip ( attrs) {
680
+ if contains_skip ( attrs) {
681
681
return true ;
682
682
}
683
683
@@ -686,10 +686,7 @@ impl<'a> FmtVisitor<'a> {
686
686
return false ;
687
687
}
688
688
689
- let rewrite = attrs. rewrite (
690
- & self . get_context ( ) ,
691
- Shape :: indented ( self . block_indent , self . config ) ,
692
- ) ;
689
+ let rewrite = attrs. rewrite ( & self . get_context ( ) , self . shape ( ) ) ;
693
690
let span = mk_sp ( attrs[ 0 ] . span . lo , attrs[ attrs. len ( ) - 1 ] . span . hi ) ;
694
691
self . push_rewrite ( span, rewrite) ;
695
692
0 commit comments