@@ -699,11 +699,25 @@ impl EmitterWriter {
699
699
. to_string ( ) ,
700
700
span : MultiSpan :: new ( ) ,
701
701
render_span : None ,
702
- list : vec ! [ ] ,
703
702
} ) ;
704
703
}
705
704
}
706
705
706
+ fn msg_with_padding ( & self , msg : & str , padding : usize ) -> String {
707
+ let padding = ( 0 ..padding)
708
+ . map ( |_| " " )
709
+ . collect :: < String > ( ) ;
710
+ msg. split ( '\n' ) . enumerate ( ) . fold ( "" . to_owned ( ) , |mut acc, x| {
711
+ if x. 0 != 0 {
712
+ acc. push_str ( "\n " ) ;
713
+ // Align every line with first one.
714
+ acc. push_str ( & padding) ;
715
+ }
716
+ acc. push_str ( & x. 1 ) ;
717
+ acc
718
+ } )
719
+ }
720
+
707
721
fn emit_message_default ( & mut self ,
708
722
msp : & MultiSpan ,
709
723
msg : & str ,
@@ -722,7 +736,10 @@ impl EmitterWriter {
722
736
draw_note_separator ( & mut buffer, 0 , max_line_num_len + 1 ) ;
723
737
buffer. append ( 0 , & level. to_string ( ) , Style :: HeaderMsg ) ;
724
738
buffer. append ( 0 , ": " , Style :: NoStyle ) ;
725
- buffer. append ( 0 , msg, Style :: NoStyle ) ;
739
+
740
+ // The extra 9 ` ` is the padding that's always needed to align to the `note: `.
741
+ let message = self . msg_with_padding ( msg, max_line_num_len + 9 ) ;
742
+ buffer. append ( 0 , & message, Style :: NoStyle ) ;
726
743
} else {
727
744
buffer. append ( 0 , & level. to_string ( ) , Style :: Level ( level. clone ( ) ) ) ;
728
745
match code {
@@ -855,7 +872,10 @@ impl EmitterWriter {
855
872
856
873
buffer. append ( 0 , & level. to_string ( ) , Style :: Level ( level. clone ( ) ) ) ;
857
874
buffer. append ( 0 , ": " , Style :: HeaderMsg ) ;
858
- buffer. append ( 0 , msg, Style :: HeaderMsg ) ;
875
+
876
+ // The extra 15 ` ` is the padding that's always needed to align to the `suggestion: `.
877
+ let message = self . msg_with_padding ( msg, max_line_num_len + 15 ) ;
878
+ buffer. append ( 0 , & message, Style :: HeaderMsg ) ;
859
879
860
880
let lines = cm. span_to_lines ( primary_span) . unwrap ( ) ;
861
881
@@ -924,51 +944,8 @@ impl EmitterWriter {
924
944
}
925
945
} ,
926
946
None => {
927
- // Diagnostic with lists need to render the list items at the
928
- // appropriate depth and composed into the body of the message.
929
- let msg = if child. list . len ( ) == 0 {
930
- // Diagnostics without lists just need the original message
931
- child. message . to_owned ( )
932
- } else {
933
- // Diagnostic with a list of items needs to be rendered with the
934
- // appropriate padding at the left to have a consistent margin with
935
- // the `note: ` text.
936
-
937
- // Add as many ` ` chars at the beggining to align the `- item`
938
- // text to the beggining of the `note: ` text. The extra 9 ` ` is
939
- // the padding that's always needed to align to the `note: `.
940
- let padding = ( 0 ..max_line_num_len + 9 )
941
- . map ( |_| " " )
942
- . collect :: < String > ( ) ;
943
-
944
- // Concatenate the message and all the list items, properly aligned
945
- child. list . iter ( ) . fold ( child. message . to_owned ( ) , |mut acc, x| {
946
- acc. push_str ( "\n " ) ;
947
- acc. push_str ( & padding) ;
948
- acc. push_str ( "- " ) ;
949
- acc. push_str ( x) ;
950
- acc
951
- } )
952
- // msg will now be:
953
- //
954
- // child.message's content
955
- // - item 1
956
- // - item 2
957
- //
958
- // and the diagnostic will look like
959
- //
960
- // error: message
961
- // --> file.rs:3:20
962
- // |
963
- // 3 | <Code>
964
- // | ^^^^ highlight
965
- // |
966
- // = help: child.message's content
967
- // - item 1
968
- // - item 2
969
- } ;
970
947
match self . emit_message_default ( & child. span ,
971
- & msg ,
948
+ & child . message ,
972
949
& None ,
973
950
& child. level ,
974
951
max_line_num_len,
0 commit comments