@@ -1715,6 +1715,7 @@ impl EmitterWriter {
1715
1715
1716
1716
fn emit_suggestion_default (
1717
1717
& mut self ,
1718
+ span : & MultiSpan ,
1718
1719
suggestion : & CodeSuggestion ,
1719
1720
args : & FluentArgs < ' _ > ,
1720
1721
level : & Level ,
@@ -1766,6 +1767,30 @@ impl EmitterWriter {
1766
1767
None ,
1767
1768
}
1768
1769
1770
+ if let Some ( span) = span. primary_span ( ) {
1771
+ // Compare the primary span of the diagnostic with the span of the suggestion
1772
+ // being emitted. If they belong to the same file, we don't *need* to show the
1773
+ // file name, saving in verbosity, but if it *isn't* we do need it, otherwise we're
1774
+ // telling users to make a change but not clarifying *where*.
1775
+ let loc = sm. lookup_char_pos ( parts[ 0 ] . span . lo ( ) ) ;
1776
+ if loc. file . name != sm. span_to_filename ( span) && loc. file . name . is_real ( ) {
1777
+ buffer. puts ( row_num - 1 , 0 , "--> " , Style :: LineNumber ) ;
1778
+ buffer. append (
1779
+ row_num - 1 ,
1780
+ & format ! (
1781
+ "{}:{}:{}" ,
1782
+ sm. filename_for_diagnostics( & loc. file. name) ,
1783
+ sm. doctest_offset_line( & loc. file. name, loc. line) ,
1784
+ loc. col. 0 + 1 ,
1785
+ ) ,
1786
+ Style :: LineAndColumn ,
1787
+ ) ;
1788
+ for _ in 0 ..max_line_num_len {
1789
+ buffer. prepend ( row_num - 1 , " " , Style :: NoStyle ) ;
1790
+ }
1791
+ row_num += 1 ;
1792
+ }
1793
+ }
1769
1794
let show_code_change = if has_deletion && !is_multiline {
1770
1795
DisplaySuggestion :: Diff
1771
1796
} else if ( parts. len ( ) != 1 || parts[ 0 ] . snippet . trim ( ) != complete. trim ( ) )
@@ -1787,7 +1812,7 @@ impl EmitterWriter {
1787
1812
assert ! ( !file_lines. lines. is_empty( ) || parts[ 0 ] . span. is_dummy( ) ) ;
1788
1813
1789
1814
let line_start = sm. lookup_char_pos ( parts[ 0 ] . span . lo ( ) ) . line ;
1790
- draw_col_separator_no_space ( & mut buffer, 1 , max_line_num_len + 1 ) ;
1815
+ draw_col_separator_no_space ( & mut buffer, row_num - 1 , max_line_num_len + 1 ) ;
1791
1816
let mut lines = complete. lines ( ) ;
1792
1817
if lines. clone ( ) . next ( ) . is_none ( ) {
1793
1818
// Account for a suggestion to completely remove a line(s) with whitespace (#94192).
@@ -2046,9 +2071,13 @@ impl EmitterWriter {
2046
2071
) {
2047
2072
panic ! ( "failed to emit error: {}" , e) ;
2048
2073
}
2049
- } else if let Err ( e) =
2050
- self . emit_suggestion_default ( sugg, args, & Level :: Help , max_line_num_len)
2051
- {
2074
+ } else if let Err ( e) = self . emit_suggestion_default (
2075
+ span,
2076
+ sugg,
2077
+ args,
2078
+ & Level :: Help ,
2079
+ max_line_num_len,
2080
+ ) {
2052
2081
panic ! ( "failed to emit error: {}" , e) ;
2053
2082
} ;
2054
2083
}
0 commit comments