@@ -2175,30 +2175,69 @@ impl EmitterWriter {
2175
2175
file_lines : & FileLines ,
2176
2176
is_multiline : bool ,
2177
2177
) {
2178
- // Print the span column to avoid confusion
2179
- buffer. puts ( * row_num, 0 , & self . maybe_anonymized ( line_start + line_pos) , Style :: LineNumber ) ;
2180
2178
if let DisplaySuggestion :: Diff = show_code_change {
2181
2179
// Add the line number for both addition and removal to drive the point home.
2182
2180
//
2183
2181
// N - fn foo<A: T>(bar: A) {
2184
2182
// N + fn foo(bar: impl T) {
2183
+ let number_of_lines = file_lines. lines . len ( ) ;
2184
+ for ( index, line_to_remove) in
2185
+ file_lines. lines . iter ( ) . take ( number_of_lines - 1 ) . enumerate ( )
2186
+ {
2187
+ buffer. puts (
2188
+ * row_num - 1 ,
2189
+ 0 ,
2190
+ & self . maybe_anonymized ( line_start + line_pos + index) ,
2191
+ Style :: LineNumber ,
2192
+ ) ;
2193
+ buffer. puts ( * row_num - 1 , max_line_num_len + 1 , "- " , Style :: Removal ) ;
2194
+ buffer. puts (
2195
+ * row_num - 1 ,
2196
+ max_line_num_len + 3 ,
2197
+ & normalize_whitespace (
2198
+ & file_lines. file . get_line ( line_to_remove. line_index ) . unwrap ( ) ,
2199
+ ) ,
2200
+ Style :: NoStyle ,
2201
+ ) ;
2202
+ * row_num += 1 ;
2203
+ }
2204
+ let last_line = & file_lines
2205
+ . file
2206
+ . get_line ( file_lines. lines [ number_of_lines - 1 ] . line_index )
2207
+ . unwrap ( ) ;
2208
+ if last_line != line {
2209
+ buffer. puts (
2210
+ * row_num - 1 ,
2211
+ 0 ,
2212
+ & self . maybe_anonymized ( line_start + line_pos + number_of_lines - 1 ) ,
2213
+ Style :: LineNumber ,
2214
+ ) ;
2215
+ buffer. puts ( * row_num - 1 , max_line_num_len + 1 , "- " , Style :: Removal ) ;
2216
+ buffer. puts (
2217
+ * row_num - 1 ,
2218
+ max_line_num_len + 3 ,
2219
+ & normalize_whitespace ( last_line) ,
2220
+ Style :: NoStyle ,
2221
+ ) ;
2222
+ buffer. puts (
2223
+ * row_num,
2224
+ 0 ,
2225
+ & self . maybe_anonymized ( line_start + line_pos) ,
2226
+ Style :: LineNumber ,
2227
+ ) ;
2228
+ buffer. puts ( * row_num, max_line_num_len + 1 , "+ " , Style :: Addition ) ;
2229
+ // print the suggestion
2230
+ buffer. append ( * row_num, & normalize_whitespace ( line) , Style :: NoStyle ) ;
2231
+ } else {
2232
+ * row_num -= 2 ;
2233
+ }
2234
+ } else if is_multiline {
2185
2235
buffer. puts (
2186
- * row_num - 1 ,
2236
+ * row_num,
2187
2237
0 ,
2188
2238
& self . maybe_anonymized ( line_start + line_pos) ,
2189
2239
Style :: LineNumber ,
2190
2240
) ;
2191
- buffer. puts ( * row_num - 1 , max_line_num_len + 1 , "- " , Style :: Removal ) ;
2192
- buffer. puts (
2193
- * row_num - 1 ,
2194
- max_line_num_len + 3 ,
2195
- & normalize_whitespace (
2196
- & file_lines. file . get_line ( file_lines. lines [ line_pos] . line_index ) . unwrap ( ) ,
2197
- ) ,
2198
- Style :: NoStyle ,
2199
- ) ;
2200
- buffer. puts ( * row_num, max_line_num_len + 1 , "+ " , Style :: Addition ) ;
2201
- } else if is_multiline {
2202
2241
match & highlight_parts[ ..] {
2203
2242
[ SubstitutionHighlight { start : 0 , end } ] if * end == line. len ( ) => {
2204
2243
buffer. puts ( * row_num, max_line_num_len + 1 , "+ " , Style :: Addition ) ;
@@ -2210,13 +2249,20 @@ impl EmitterWriter {
2210
2249
buffer. puts ( * row_num, max_line_num_len + 1 , "~ " , Style :: Addition ) ;
2211
2250
}
2212
2251
}
2252
+ // print the suggestion
2253
+ buffer. append ( * row_num, & normalize_whitespace ( line) , Style :: NoStyle ) ;
2213
2254
} else {
2255
+ buffer. puts (
2256
+ * row_num,
2257
+ 0 ,
2258
+ & self . maybe_anonymized ( line_start + line_pos) ,
2259
+ Style :: LineNumber ,
2260
+ ) ;
2214
2261
draw_col_separator ( buffer, * row_num, max_line_num_len + 1 ) ;
2262
+ // print the suggestion
2263
+ buffer. append ( * row_num, & normalize_whitespace ( line) , Style :: NoStyle ) ;
2215
2264
}
2216
2265
2217
- // print the suggestion
2218
- buffer. append ( * row_num, & normalize_whitespace ( line) , Style :: NoStyle ) ;
2219
-
2220
2266
// Colorize addition/replacements with green.
2221
2267
for & SubstitutionHighlight { start, end } in highlight_parts {
2222
2268
// Account for tabs when highlighting (#87972).
0 commit comments