@@ -468,8 +468,10 @@ impl fmt::Display for ErrorKind {
468
468
469
469
// Formatting errors that are identified *after* rustfmt has run.
470
470
pub struct FormattingError {
471
- line : u32 ,
471
+ line : usize ,
472
472
kind : ErrorKind ,
473
+ is_comment : bool ,
474
+ line_buffer : String ,
473
475
}
474
476
475
477
impl FormattingError {
@@ -600,6 +602,7 @@ fn format_lines(text: &mut StringBuffer, name: &str, config: &Config, report: &m
600
602
let mut issue_seeker = BadIssueSeeker :: new ( config. report_todo ( ) , config. report_fixme ( ) ) ;
601
603
let mut prev_char: Option < char > = None ;
602
604
let mut is_comment = false ;
605
+ let mut line_buffer = String :: with_capacity ( config. max_width ( ) * 2 ) ;
603
606
604
607
for ( c, b) in text. chars ( ) {
605
608
if c == '\r' {
@@ -614,6 +617,8 @@ fn format_lines(text: &mut StringBuffer, name: &str, config: &Config, report: &m
614
617
errors. push ( FormattingError {
615
618
line : cur_line,
616
619
kind : ErrorKind :: BadIssue ( issue) ,
620
+ is_comment : false ,
621
+ line_buffer : String :: new ( ) ,
617
622
} ) ;
618
623
}
619
624
}
@@ -622,7 +627,7 @@ fn format_lines(text: &mut StringBuffer, name: &str, config: &Config, report: &m
622
627
if format_line {
623
628
// Check for (and record) trailing whitespace.
624
629
if let Some ( lw) = last_wspace {
625
- trims. push ( ( cur_line, lw, b) ) ;
630
+ trims. push ( ( cur_line, lw, b, line_buffer . clone ( ) ) ) ;
626
631
line_len -= 1 ;
627
632
}
628
633
@@ -633,6 +638,8 @@ fn format_lines(text: &mut StringBuffer, name: &str, config: &Config, report: &m
633
638
errors. push ( FormattingError {
634
639
line : cur_line,
635
640
kind : ErrorKind :: LineOverflow ( line_len, config. max_width ( ) ) ,
641
+ is_comment : is_comment,
642
+ line_buffer : line_buffer. clone ( ) ,
636
643
} ) ;
637
644
}
638
645
}
@@ -643,6 +650,7 @@ fn format_lines(text: &mut StringBuffer, name: &str, config: &Config, report: &m
643
650
last_wspace = None ;
644
651
prev_char = None ;
645
652
is_comment = false ;
653
+ line_buffer. clear ( ) ;
646
654
} else {
647
655
newline_count = 0 ;
648
656
line_len += 1 ;
@@ -660,6 +668,7 @@ fn format_lines(text: &mut StringBuffer, name: &str, config: &Config, report: &m
660
668
last_wspace = None ;
661
669
}
662
670
prev_char = Some ( c) ;
671
+ line_buffer. push ( c) ;
663
672
}
664
673
}
665
674
@@ -669,10 +678,12 @@ fn format_lines(text: &mut StringBuffer, name: &str, config: &Config, report: &m
669
678
text. truncate ( line) ;
670
679
}
671
680
672
- for & ( l, _, _) in & trims {
681
+ for & ( l, _, _, ref b ) in & trims {
673
682
errors. push ( FormattingError {
674
683
line : l,
675
684
kind : ErrorKind :: TrailingWhitespace ,
685
+ is_comment : false ,
686
+ line_buffer : b. clone ( ) ,
676
687
} ) ;
677
688
}
678
689
0 commit comments