@@ -703,10 +703,29 @@ impl EmitterWriter {
703
703
}
704
704
}
705
705
706
- fn msg_with_padding ( & self , msg : & str , padding : usize ) -> String {
707
- let padding = ( 0 ..padding)
706
+ /// Add a left margin to every line but the first, given a padding length and the label being
707
+ /// displayed.
708
+ fn msg_with_padding ( & self , msg : & str , padding : usize , label : & str ) -> String {
709
+ // The extra 5 ` ` is padding that's always needed to align to the `note: `:
710
+ //
711
+ // error: message
712
+ // --> file.rs:13:20
713
+ // |
714
+ // 13 | <CODE>
715
+ // | ^^^^
716
+ // |
717
+ // = note: multiline
718
+ // message
719
+ // ++^^^----xx
720
+ // | | | |
721
+ // | | | magic `2`
722
+ // | | length of label
723
+ // | magic `3`
724
+ // `max_line_num_len`
725
+ let padding = ( 0 ..padding + label. len ( ) + 5 )
708
726
. map ( |_| " " )
709
727
. collect :: < String > ( ) ;
728
+
710
729
msg. split ( '\n' ) . enumerate ( ) . fold ( "" . to_owned ( ) , |mut acc, x| {
711
730
if x. 0 != 0 {
712
731
acc. push_str ( "\n " ) ;
@@ -737,8 +756,7 @@ impl EmitterWriter {
737
756
buffer. append ( 0 , & level. to_string ( ) , Style :: HeaderMsg ) ;
738
757
buffer. append ( 0 , ": " , Style :: NoStyle ) ;
739
758
740
- // The extra 3 ` ` is the padding that's always needed to align to the `note: `.
741
- let message = self . msg_with_padding ( msg, max_line_num_len + "note: " . len ( ) + 3 ) ;
759
+ let message = self . msg_with_padding ( msg, max_line_num_len, "note" ) ;
742
760
buffer. append ( 0 , & message, Style :: NoStyle ) ;
743
761
} else {
744
762
buffer. append ( 0 , & level. to_string ( ) , Style :: Level ( level. clone ( ) ) ) ;
@@ -873,8 +891,7 @@ impl EmitterWriter {
873
891
buffer. append ( 0 , & level. to_string ( ) , Style :: Level ( level. clone ( ) ) ) ;
874
892
buffer. append ( 0 , ": " , Style :: HeaderMsg ) ;
875
893
876
- // The extra 3 ` ` is the padding that's always needed to align to the `suggestion: `.
877
- let message = self . msg_with_padding ( msg, max_line_num_len + "suggestion: " . len ( ) + 3 ) ;
894
+ let message = self . msg_with_padding ( msg, max_line_num_len, "suggestion" ) ;
878
895
buffer. append ( 0 , & message, Style :: HeaderMsg ) ;
879
896
880
897
let lines = cm. span_to_lines ( primary_span) . unwrap ( ) ;
0 commit comments