@@ -1976,9 +1976,11 @@ impl HumanEmitter {
1976
1976
Some ( Style :: HeaderMsg ) ,
1977
1977
) ;
1978
1978
1979
+ let other_suggestions = suggestions. len ( ) . saturating_sub ( MAX_SUGGESTIONS ) ;
1980
+
1979
1981
let mut row_num = 2 ;
1980
1982
for ( i, ( complete, parts, highlights, _) ) in
1981
- suggestions. iter ( ) . enumerate ( ) . take ( MAX_SUGGESTIONS )
1983
+ suggestions. into_iter ( ) . enumerate ( ) . take ( MAX_SUGGESTIONS )
1982
1984
{
1983
1985
debug ! ( ?complete, ?parts, ?highlights) ;
1984
1986
@@ -2168,7 +2170,7 @@ impl HumanEmitter {
2168
2170
self . draw_code_line (
2169
2171
& mut buffer,
2170
2172
& mut row_num,
2171
- highlight_parts,
2173
+ & highlight_parts,
2172
2174
line_pos + line_start,
2173
2175
line,
2174
2176
show_code_change,
@@ -2214,7 +2216,12 @@ impl HumanEmitter {
2214
2216
if let DisplaySuggestion :: Diff | DisplaySuggestion :: Underline | DisplaySuggestion :: Add =
2215
2217
show_code_change
2216
2218
{
2217
- for part in parts {
2219
+ for mut part in parts {
2220
+ // If this is a replacement of, e.g. `"a"` into `"ab"`, adjust the
2221
+ // suggestion and snippet to look as if we just suggested to add
2222
+ // `"b"`, which is typically much easier for the user to understand.
2223
+ part. trim_trivial_replacements ( sm) ;
2224
+
2218
2225
let snippet = if let Ok ( snippet) = sm. span_to_snippet ( part. span ) {
2219
2226
snippet
2220
2227
} else {
@@ -2377,9 +2384,12 @@ impl HumanEmitter {
2377
2384
row_num = row + 1 ;
2378
2385
}
2379
2386
}
2380
- if suggestions. len ( ) > MAX_SUGGESTIONS {
2381
- let others = suggestions. len ( ) - MAX_SUGGESTIONS ;
2382
- let msg = format ! ( "and {} other candidate{}" , others, pluralize!( others) ) ;
2387
+ if other_suggestions > 0 {
2388
+ let msg = format ! (
2389
+ "and {} other candidate{}" ,
2390
+ other_suggestions,
2391
+ pluralize!( other_suggestions)
2392
+ ) ;
2383
2393
buffer. puts ( row_num, max_line_num_len + 3 , & msg, Style :: NoStyle ) ;
2384
2394
}
2385
2395
0 commit comments