@@ -1976,9 +1976,11 @@ impl HumanEmitter {
19761976 Some ( Style :: HeaderMsg ) ,
19771977 ) ;
19781978
1979+ let other_suggestions = suggestions. len ( ) . saturating_sub ( MAX_SUGGESTIONS ) ;
1980+
19791981 let mut row_num = 2 ;
19801982 for ( i, ( complete, parts, highlights, _) ) in
1981- suggestions. iter ( ) . enumerate ( ) . take ( MAX_SUGGESTIONS )
1983+ suggestions. into_iter ( ) . enumerate ( ) . take ( MAX_SUGGESTIONS )
19821984 {
19831985 debug ! ( ?complete, ?parts, ?highlights) ;
19841986
@@ -2168,7 +2170,7 @@ impl HumanEmitter {
21682170 self . draw_code_line (
21692171 & mut buffer,
21702172 & mut row_num,
2171- highlight_parts,
2173+ & highlight_parts,
21722174 line_pos + line_start,
21732175 line,
21742176 show_code_change,
@@ -2214,7 +2216,12 @@ impl HumanEmitter {
22142216 if let DisplaySuggestion :: Diff | DisplaySuggestion :: Underline | DisplaySuggestion :: Add =
22152217 show_code_change
22162218 {
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+
22182225 let snippet = if let Ok ( snippet) = sm. span_to_snippet ( part. span ) {
22192226 snippet
22202227 } else {
@@ -2377,9 +2384,12 @@ impl HumanEmitter {
23772384 row_num = row + 1 ;
23782385 }
23792386 }
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+ ) ;
23832393 buffer. puts ( row_num, max_line_num_len + 3 , & msg, Style :: NoStyle ) ;
23842394 }
23852395
0 commit comments