@@ -63,7 +63,10 @@ impl<'a> FmtVisitor<'a> {
6363 let config = self . config ;
6464 self . format_missing_inner ( end, |this, last_snippet, snippet| {
6565 this. push_str ( last_snippet. trim_end ( ) ) ;
66- if last_snippet == snippet && !this. output_at_start ( ) {
66+ if last_snippet == snippet
67+ && !this. output_at_start ( )
68+ && !out_of_file_lines_range ! ( this, mk_sp( this. last_pos, end) )
69+ {
6770 // No new lines in the snippet.
6871 this. push_str ( "\n " ) ;
6972 }
@@ -100,7 +103,11 @@ impl<'a> FmtVisitor<'a> {
100103 let snippet = self . snippet ( span) ;
101104
102105 // Do nothing for spaces in the beginning of the file
103- if start == BytePos ( 0 ) && end. 0 as usize == snippet. len ( ) && snippet. trim ( ) . is_empty ( ) {
106+ if start == BytePos ( 0 )
107+ && end. 0 as usize == snippet. len ( )
108+ && snippet. trim ( ) . is_empty ( )
109+ && !out_of_file_lines_range ! ( self , span)
110+ {
104111 return ;
105112 }
106113
@@ -357,11 +364,20 @@ impl<'a> FmtVisitor<'a> {
357364 }
358365 }
359366
360- let remaining = snippet[ status. line_start ..subslice. len ( ) + offset] . trim ( ) ;
361- if !remaining. is_empty ( ) {
362- self . push_str ( & self . block_indent . to_string ( self . config ) ) ;
363- self . push_str ( remaining) ;
364- status. line_start = subslice. len ( ) + offset;
367+ let mut remaining = & snippet[ status. line_start ..subslice. len ( ) + offset] ;
368+ status. line_start = subslice. len ( ) + offset;
369+
370+ let skip_this_line = !self
371+ . config
372+ . file_lines ( )
373+ . contains_line ( file_name, status. cur_line ) ;
374+ if !skip_this_line {
375+ remaining = remaining. trim ( ) ;
376+ if !remaining. is_empty ( ) {
377+ self . push_str ( & self . block_indent . to_string ( self . config ) ) ;
378+ }
365379 }
380+
381+ self . push_str ( remaining) ;
366382 }
367383}
0 commit comments