@@ -214,7 +214,7 @@ pub trait Emitter {
214
214
215
215
/// Formats the substitutions of the primary_span
216
216
///
217
- /// The are a lot of conditions to this method, but in short:
217
+ /// There are a lot of conditions to this method, but in short:
218
218
///
219
219
/// * If the current `Diagnostic` has only one visible `CodeSuggestion`,
220
220
/// we format the `help` suggestion depending on the content of the
@@ -736,7 +736,9 @@ impl EmitterWriter {
736
736
737
737
let line_offset = buffer. num_lines ( ) ;
738
738
739
- let left = margin. left ( source_string. len ( ) ) ; // Left trim
739
+ // Left trim
740
+ let left = margin. left ( source_string. len ( ) ) ;
741
+
740
742
// Account for unicode characters of width !=0 that were removed.
741
743
let left = source_string
742
744
. chars ( )
@@ -1623,18 +1625,27 @@ impl EmitterWriter {
1623
1625
suggestions. iter ( ) . take ( MAX_SUGGESTIONS )
1624
1626
{
1625
1627
notice_capitalization |= only_capitalization;
1626
- // Only show underline if the suggestion spans a single line and doesn't cover the
1627
- // entirety of the code output. If you have multiple replacements in the same line
1628
- // of code, show the underline.
1629
- let show_underline = !( parts. len ( ) == 1 && parts[ 0 ] . snippet . trim ( ) == complete. trim ( ) )
1630
- && complete. lines ( ) . count ( ) == 1 ;
1631
1628
1632
1629
let has_deletion = parts. iter ( ) . any ( |p| p. is_deletion ( ) ) ;
1633
1630
let is_multiline = complete. lines ( ) . count ( ) > 1 ;
1634
1631
1635
- let show_diff = has_deletion && !is_multiline;
1632
+ enum DisplaySuggestion {
1633
+ Underline ,
1634
+ Diff ,
1635
+ None ,
1636
+ }
1637
+
1638
+ let show_code_change = if has_deletion && !is_multiline {
1639
+ DisplaySuggestion :: Diff
1640
+ } else if ( parts. len ( ) != 1 || parts[ 0 ] . snippet . trim ( ) != complete. trim ( ) )
1641
+ && !is_multiline
1642
+ {
1643
+ DisplaySuggestion :: Underline
1644
+ } else {
1645
+ DisplaySuggestion :: None
1646
+ } ;
1636
1647
1637
- if show_diff {
1648
+ if let DisplaySuggestion :: Diff = show_code_change {
1638
1649
row_num += 1 ;
1639
1650
}
1640
1651
@@ -1657,7 +1668,7 @@ impl EmitterWriter {
1657
1668
& self . maybe_anonymized ( line_start + line_pos) ,
1658
1669
Style :: LineNumber ,
1659
1670
) ;
1660
- if show_diff {
1671
+ if let DisplaySuggestion :: Diff = show_code_change {
1661
1672
// Add the line number for both addition and removal to drive the point home.
1662
1673
//
1663
1674
// N - fn foo<A: T>(bar: A) {
@@ -1727,7 +1738,7 @@ impl EmitterWriter {
1727
1738
let mut offsets: Vec < ( usize , isize ) > = Vec :: new ( ) ;
1728
1739
// Only show an underline in the suggestions if the suggestion is not the
1729
1740
// entirety of the code being shown and the displayed code is not multiline.
1730
- if show_underline {
1741
+ if let DisplaySuggestion :: Diff | DisplaySuggestion :: Underline = show_code_change {
1731
1742
draw_col_separator ( & mut buffer, row_num, max_line_num_len + 1 ) ;
1732
1743
for part in parts {
1733
1744
let span_start_pos = sm. lookup_char_pos ( part. span . lo ( ) ) . col_display ;
@@ -1755,7 +1766,7 @@ impl EmitterWriter {
1755
1766
assert ! ( underline_start >= 0 && underline_end >= 0 ) ;
1756
1767
let padding: usize = max_line_num_len + 3 ;
1757
1768
for p in underline_start..underline_end {
1758
- if !show_diff {
1769
+ if let DisplaySuggestion :: Underline = show_code_change {
1759
1770
// If this is a replacement, underline with `^`, if this is an addition
1760
1771
// underline with `+`.
1761
1772
buffer. putc (
@@ -1766,7 +1777,7 @@ impl EmitterWriter {
1766
1777
) ;
1767
1778
}
1768
1779
}
1769
- if show_diff {
1780
+ if let DisplaySuggestion :: Diff = show_code_change {
1770
1781
// Colorize removal with red in diff format.
1771
1782
buffer. set_style_range (
1772
1783
row_num - 2 ,
@@ -1797,7 +1808,7 @@ impl EmitterWriter {
1797
1808
// if we elided some lines, add an ellipsis
1798
1809
if lines. next ( ) . is_some ( ) {
1799
1810
buffer. puts ( row_num, max_line_num_len - 1 , "..." , Style :: LineNumber ) ;
1800
- } else if !show_underline {
1811
+ } else if let DisplaySuggestion :: None = show_code_change {
1801
1812
draw_col_separator_no_space ( & mut buffer, row_num, max_line_num_len + 1 ) ;
1802
1813
row_num += 1 ;
1803
1814
}
@@ -2083,7 +2094,7 @@ const OUTPUT_REPLACEMENTS: &[(char, &str)] = &[
2083
2094
( '\t' , " " ) , // We do our own tab replacement
2084
2095
( '\u{200D}' , "" ) , // Replace ZWJ with nothing for consistent terminal output of grapheme clusters.
2085
2096
( '\u{202A}' , "" ) , // The following unicode text flow control characters are inconsistently
2086
- ( '\u{202B}' , "" ) , // supported accross CLIs and can cause confusion due to the bytes on disk
2097
+ ( '\u{202B}' , "" ) , // supported across CLIs and can cause confusion due to the bytes on disk
2087
2098
( '\u{202D}' , "" ) , // not corresponding to the visible source code, so we replace them always.
2088
2099
( '\u{202E}' , "" ) ,
2089
2100
( '\u{2066}' , "" ) ,
0 commit comments