@@ -1060,11 +1060,11 @@ impl EmitterWriter {
1060
1060
-> io:: Result < ( ) > {
1061
1061
use std:: borrow:: Borrow ;
1062
1062
1063
- let primary_span = suggestion. substitution_spans ( ) . next ( ) . unwrap ( ) ;
1063
+ let primary_sub = & suggestion. substitution_parts [ 0 ] ;
1064
1064
if let Some ( ref cm) = self . cm {
1065
1065
let mut buffer = StyledBuffer :: new ( ) ;
1066
1066
1067
- let lines = cm. span_to_lines ( primary_span ) . unwrap ( ) ;
1067
+ let lines = cm. span_to_lines ( primary_sub . span ) . unwrap ( ) ;
1068
1068
1069
1069
assert ! ( !lines. lines. is_empty( ) ) ;
1070
1070
@@ -1077,26 +1077,51 @@ impl EmitterWriter {
1077
1077
Some ( Style :: HeaderMsg ) ) ;
1078
1078
1079
1079
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 ;
1082
1085
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 ;
1083
1091
1084
1092
let mut lines = complete. lines ( ) ;
1085
1093
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
1087
1095
buffer. puts ( row_num,
1088
1096
0 ,
1089
- & ( ( line_start + row_num ) . to_string ( ) ) ,
1097
+ & ( ( line_start + line_pos ) . to_string ( ) ) ,
1090
1098
Style :: LineNumber ) ;
1091
1099
// print the suggestion
1092
1100
draw_col_separator ( & mut buffer, row_num, max_line_num_len + 1 ) ;
1093
1101
buffer. append ( row_num, line, Style :: NoStyle ) ;
1094
1102
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 ;
1095
1118
}
1096
1119
1097
1120
// if we elided some lines, add an ellipsis
1098
1121
if let Some ( _) = lines. next ( ) {
1099
1122
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 ) ;
1100
1125
}
1101
1126
}
1102
1127
if suggestions. len ( ) > MAX_SUGGESTIONS {
0 commit comments