@@ -562,17 +562,37 @@ impl Renderer {
562562 is_cont,
563563 ) ;
564564
565- if title. level . name != Some ( None ) {
565+ let label_width = if title. level . name != Some ( None ) {
566566 buffer. append (
567567 buffer_msg_line_offset,
568568 title. level . as_str ( ) ,
569569 ElementStyle :: MainHeaderMsg ,
570570 ) ;
571571 buffer. append ( buffer_msg_line_offset, ": " , ElementStyle :: NoStyle ) ;
572- }
572+ title. level . as_str ( ) . len ( ) + 2
573+ } else {
574+ 0
575+ } ;
576+ // The extra 3 ` ` is padding that's always needed to align to the
577+ // label i.e. `note: `:
578+ //
579+ // error: message
580+ // --> file.rs:13:20
581+ // |
582+ // 13 | <CODE>
583+ // | ^^^^
584+ // |
585+ // = note: multiline
586+ // message
587+ // ++^^^------
588+ // | | |
589+ // | | |
590+ // | | width of label
591+ // | magic `3`
592+ // `max_line_num_len`
593+ let padding = max_line_num_len + 3 + label_width;
573594
574- let printed_lines =
575- self . msgs_to_buffer ( buffer, title. title , max_line_num_len, "note" , None ) ;
595+ let printed_lines = self . msgs_to_buffer ( buffer, title. title , padding, None ) ;
576596 if is_cont && matches ! ( self . theme, OutputTheme :: Unicode ) {
577597 // There's another note after this one, associated to the subwindow above.
578598 // We write additional vertical lines to join them:
@@ -660,26 +680,9 @@ impl Renderer {
660680 buffer : & mut StyledBuffer ,
661681 title : & str ,
662682 padding : usize ,
663- label : & str ,
664683 override_style : Option < ElementStyle > ,
665684 ) -> usize {
666- // The extra 5 ` ` is padding that's always needed to align to the `note: `:
667- //
668- // error: message
669- // --> file.rs:13:20
670- // |
671- // 13 | <CODE>
672- // | ^^^^
673- // |
674- // = note: multiline
675- // message
676- // ++^^^----xx
677- // | | | |
678- // | | | magic `2`
679- // | | length of label
680- // | magic `3`
681- // `max_line_num_len`
682- let padding = " " . repeat ( padding + label. len ( ) + 5 ) ;
685+ let padding = " " . repeat ( padding) ;
683686
684687 let mut line_number = buffer. num_lines ( ) . saturating_sub ( 1 ) ;
685688
0 commit comments