@@ -34,18 +34,16 @@ impl DisplayListFormatting for Formatter {
3434 )
3535 }
3636
37- fn format_annotation_content (
37+ fn format_source_annotation_lines (
38+ f : & mut fmt:: Formatter ,
39+ lineno_width : usize ,
40+ inline_marks : String ,
3841 range : & ( usize , usize ) ,
3942 label : & [ DisplayTextFragment ] ,
4043 annotation_type : & DisplayAnnotationType ,
4144 annotation_part : & DisplayAnnotationPart ,
42- ) -> String {
43- let label = if label. is_empty ( ) {
44- "" . to_string ( )
45- } else {
46- format ! ( " {}" , Self :: format_label( label) )
47- } ;
48- let prefix = match annotation_part {
45+ ) -> fmt:: Result {
46+ let indent_char = match annotation_part {
4947 DisplayAnnotationPart :: Singleline => " " ,
5048 DisplayAnnotationPart :: MultilineStart => "_" ,
5149 DisplayAnnotationPart :: MultilineEnd => "_" ,
@@ -62,12 +60,48 @@ impl DisplayListFormatting for Formatter {
6260 DisplayAnnotationType :: Note => Style :: new ( ) . bold ( ) ,
6361 DisplayAnnotationType :: Help => Fixed ( 14 ) . bold ( ) ,
6462 } ;
65- format ! (
66- "{}{}{}" ,
67- prefix. repeat( range. 0 ) ,
68- color. paint( mark. repeat( range. 1 - range. 0 ) ) ,
69- color. paint( label) ,
70- )
63+ if let Some ( ( first, rest) ) = Self :: format_label ( label)
64+ . lines ( )
65+ . collect :: < Vec < & str > > ( )
66+ . split_first ( )
67+ {
68+ let indent = range. 1 ;
69+ writeln ! (
70+ f,
71+ "{}{}{}{} {}" ,
72+ Fixed ( 12 )
73+ . bold( )
74+ . paint( format!( "{} |" , " " . repeat( lineno_width) ) ) ,
75+ inline_marks,
76+ indent_char. repeat( range. 0 ) ,
77+ color. paint( mark. repeat( range. 1 - range. 0 ) ) ,
78+ color. paint( * first) ,
79+ ) ?;
80+ for line in rest {
81+ writeln ! (
82+ f,
83+ "{}{}{} {}" ,
84+ Fixed ( 12 )
85+ . bold( )
86+ . paint( format!( "{} |" , " " . repeat( lineno_width) ) ) ,
87+ inline_marks,
88+ " " . repeat( indent) ,
89+ color. paint( * line) ,
90+ ) ?;
91+ }
92+ } else {
93+ writeln ! (
94+ f,
95+ "{}{}{}{}" ,
96+ Fixed ( 12 )
97+ . bold( )
98+ . paint( format!( "{} |" , " " . repeat( lineno_width) ) ) ,
99+ inline_marks,
100+ indent_char. repeat( range. 0 ) ,
101+ color. paint( mark. repeat( range. 1 - range. 0 ) ) ,
102+ ) ?;
103+ }
104+ Ok ( ( ) )
71105 }
72106
73107 fn format_label ( label : & [ DisplayTextFragment ] ) -> String {
@@ -185,21 +219,15 @@ impl DisplayListFormatting for Formatter {
185219 label,
186220 annotation_type,
187221 annotation_part,
188- } => {
189- let prefix = format ! ( "{} |" , " " . repeat( lineno_width) ) ;
190- writeln ! (
191- f,
192- "{}{}{}" ,
193- Fixed ( 12 ) . bold( ) . paint( prefix) ,
194- Self :: format_inline_marks( & inline_marks, inline_marks_width) ,
195- Self :: format_annotation_content(
196- range,
197- & label,
198- & annotation_type,
199- & annotation_part
200- ) ,
201- )
202- }
222+ } => Self :: format_source_annotation_lines (
223+ f,
224+ lineno_width,
225+ Self :: format_inline_marks ( & inline_marks, inline_marks_width) ,
226+ range,
227+ & label,
228+ & annotation_type,
229+ & annotation_part,
230+ ) ,
203231 DisplayLine :: Fold { inline_marks } => writeln ! (
204232 f,
205233 "... {}" ,
0 commit comments