@@ -516,8 +516,7 @@ fn format_lines(
516
516
config : & Config ,
517
517
report : & FormatReport ,
518
518
) {
519
- let mut trims = vec ! [ ] ;
520
- let mut last_wspace: Option < usize > = None ;
519
+ let mut last_was_space = false ;
521
520
let mut line_len = 0 ;
522
521
let mut cur_line = 1 ;
523
522
let mut newline_count = 0 ;
@@ -542,7 +541,7 @@ fn format_lines(
542
541
}
543
542
544
543
// Iterate over the chars in the file map.
545
- for ( kind, ( b , c ) ) in CharClasses :: new ( text. chars ( ) . enumerate ( ) ) {
544
+ for ( kind, c ) in CharClasses :: new ( text. chars ( ) ) {
546
545
if c == '\r' {
547
546
continue ;
548
547
}
@@ -563,10 +562,17 @@ fn format_lines(
563
562
if c == '\n' {
564
563
if format_line {
565
564
// Check for (and record) trailing whitespace.
566
- if let Some ( .. ) = last_wspace {
565
+ if last_was_space {
567
566
if should_report_error ( config, kind, is_string, & ErrorKind :: TrailingWhitespace )
567
+ && !is_skipped_line ( cur_line, skipped_range)
568
568
{
569
- trims. push ( ( cur_line, kind, line_buffer. clone ( ) ) ) ;
569
+ errors. push ( FormattingError {
570
+ line : cur_line,
571
+ kind : ErrorKind :: TrailingWhitespace ,
572
+ is_comment : kind. is_comment ( ) ,
573
+ is_string : kind. is_string ( ) ,
574
+ line_buffer : line_buffer. clone ( ) ,
575
+ } ) ;
570
576
}
571
577
line_len -= 1 ;
572
578
}
@@ -591,19 +597,13 @@ fn format_lines(
591
597
cur_line += 1 ;
592
598
format_line = config. file_lines ( ) . contains_line ( name, cur_line) ;
593
599
newline_count += 1 ;
594
- last_wspace = None ;
600
+ last_was_space = false ;
595
601
line_buffer. clear ( ) ;
596
602
is_string = false ;
597
603
} else {
598
604
newline_count = 0 ;
599
605
line_len += if c == '\t' { config. tab_spaces ( ) } else { 1 } ;
600
- if c. is_whitespace ( ) {
601
- if last_wspace. is_none ( ) {
602
- last_wspace = Some ( b) ;
603
- }
604
- } else {
605
- last_wspace = None ;
606
- }
606
+ last_was_space = c. is_whitespace ( ) ;
607
607
line_buffer. push ( c) ;
608
608
if kind. is_string ( ) {
609
609
is_string = true ;
@@ -617,18 +617,6 @@ fn format_lines(
617
617
text. truncate ( line) ;
618
618
}
619
619
620
- for & ( l, kind, ref b) in & trims {
621
- if !is_skipped_line ( l, skipped_range) {
622
- errors. push ( FormattingError {
623
- line : l,
624
- kind : ErrorKind :: TrailingWhitespace ,
625
- is_comment : kind. is_comment ( ) ,
626
- is_string : kind. is_string ( ) ,
627
- line_buffer : b. clone ( ) ,
628
- } ) ;
629
- }
630
- }
631
-
632
620
report. append ( name. clone ( ) , errors) ;
633
621
}
634
622
0 commit comments