@@ -1886,6 +1886,7 @@ impl EmitterWriter {
1886
1886
}
1887
1887
let mut unhighlighted_lines = Vec :: new ( ) ;
1888
1888
let mut last_pos = 0 ;
1889
+ let mut is_item_attribute = false ;
1889
1890
for ( line_pos, ( line, highlight_parts) ) in lines. by_ref ( ) . zip ( highlights) . enumerate ( ) {
1890
1891
last_pos = line_pos;
1891
1892
debug ! ( %line_pos, %line, ?highlight_parts) ;
@@ -1895,6 +1896,12 @@ impl EmitterWriter {
1895
1896
unhighlighted_lines. push ( ( line_pos, line) ) ;
1896
1897
continue ;
1897
1898
}
1899
+ if highlight_parts. len ( ) == 1
1900
+ && line. trim ( ) . starts_with ( "#[" )
1901
+ && line. trim ( ) . ends_with ( ']' )
1902
+ {
1903
+ is_item_attribute = true ;
1904
+ }
1898
1905
1899
1906
match unhighlighted_lines. len ( ) {
1900
1907
0 => ( ) ,
@@ -1971,11 +1978,13 @@ impl EmitterWriter {
1971
1978
is_multiline,
1972
1979
)
1973
1980
}
1974
- if let DisplaySuggestion :: Add = show_code_change {
1981
+ if let DisplaySuggestion :: Add = show_code_change && is_item_attribute {
1975
1982
// The suggestion adds an entire line of code, ending on a newline, so we'll also
1976
1983
// print the *following* line, to provide context of what we're advicing people to
1977
1984
// do. Otherwise you would only see contextless code that can be confused for
1978
1985
// already existing code, despite the colors and UI elements.
1986
+ // We special case `#[derive(_)]\n` and other attribute suggestions, because those
1987
+ // are the ones where context is most useful.
1979
1988
let file_lines = sm
1980
1989
. span_to_lines ( span. primary_span ( ) . unwrap ( ) . shrink_to_hi ( ) )
1981
1990
. expect ( "span_to_lines failed when emitting suggestion" ) ;
0 commit comments