@@ -1060,11 +1060,11 @@ impl EmitterWriter {
10601060 -> io:: Result < ( ) > {
10611061 use std:: borrow:: Borrow ;
10621062
1063- let primary_span = suggestion. substitution_spans ( ) . next ( ) . unwrap ( ) ;
1063+ let primary_sub = & suggestion. substitution_parts [ 0 ] ;
10641064 if let Some ( ref cm) = self . cm {
10651065 let mut buffer = StyledBuffer :: new ( ) ;
10661066
1067- let lines = cm. span_to_lines ( primary_span ) . unwrap ( ) ;
1067+ let lines = cm. span_to_lines ( primary_sub . span ) . unwrap ( ) ;
10681068
10691069 assert ! ( !lines. lines. is_empty( ) ) ;
10701070
@@ -1077,26 +1077,51 @@ impl EmitterWriter {
10771077 Some ( Style :: HeaderMsg ) ) ;
10781078
10791079 let suggestions = suggestion. splice_lines ( cm. borrow ( ) ) ;
1080- let line_start = cm. lookup_char_pos ( primary_span. lo ) . line - 1 ;
1081- let mut row_num = 1 ;
1080+ let span_start_pos = cm. lookup_char_pos ( primary_sub. span . lo ) ;
1081+ let span_end_pos = cm. lookup_char_pos ( primary_sub. span . hi ) ;
1082+ let line_start = span_start_pos. line ;
1083+ draw_col_separator_no_space ( & mut buffer, 1 , max_line_num_len + 1 ) ;
1084+ let mut row_num = 2 ;
10821085 for complete in suggestions. iter ( ) . take ( MAX_SUGGESTIONS ) {
1086+ let mut line_pos = 0 ;
1087+ // Only show underline if there's a single suggestion and it is a single line
1088+ let show_underline = complete. lines ( ) . count ( ) == 1
1089+ && span_start_pos. line == span_end_pos. line
1090+ && primary_sub. substitutions . len ( ) == 1 ;
10831091
10841092 let mut lines = complete. lines ( ) ;
10851093 for line in lines. by_ref ( ) . take ( MAX_HIGHLIGHT_LINES ) {
1086- // print the span column to avoid confusion
1094+ // Print the span column to avoid confusion
10871095 buffer. puts ( row_num,
10881096 0 ,
1089- & ( ( line_start + row_num ) . to_string ( ) ) ,
1097+ & ( ( line_start + line_pos ) . to_string ( ) ) ,
10901098 Style :: LineNumber ) ;
10911099 // print the suggestion
10921100 draw_col_separator ( & mut buffer, row_num, max_line_num_len + 1 ) ;
10931101 buffer. append ( row_num, line, Style :: NoStyle ) ;
10941102 row_num += 1 ;
1103+ if show_underline {
1104+ draw_col_separator ( & mut buffer, row_num, max_line_num_len + 1 ) ;
1105+
1106+ let sub_len = primary_sub. substitutions [ 0 ] . trim_right ( ) . len ( ) ;
1107+ let underline_start = span_start_pos. col . 0 ;
1108+ let underline_end = span_start_pos. col . 0 + sub_len;
1109+ for p in underline_start..underline_end {
1110+ buffer. putc ( row_num,
1111+ max_line_num_len + 3 + p,
1112+ '^' ,
1113+ Style :: UnderlinePrimary ) ;
1114+ }
1115+ row_num += 1 ;
1116+ }
1117+ line_pos += 1 ;
10951118 }
10961119
10971120 // if we elided some lines, add an ellipsis
10981121 if let Some ( _) = lines. next ( ) {
10991122 buffer. append ( row_num, "..." , Style :: NoStyle ) ;
1123+ } else if !show_underline && suggestions. len ( ) <= MAX_SUGGESTIONS {
1124+ draw_col_separator_no_space ( & mut buffer, row_num, max_line_num_len + 1 ) ;
11001125 }
11011126 }
11021127 if suggestions. len ( ) > MAX_SUGGESTIONS {
0 commit comments