@@ -1886,6 +1886,7 @@ impl EmitterWriter {
18861886 }
18871887 let mut unhighlighted_lines = Vec :: new ( ) ;
18881888 let mut last_pos = 0 ;
1889+ let mut is_item_attribute = false ;
18891890 for ( line_pos, ( line, highlight_parts) ) in lines. by_ref ( ) . zip ( highlights) . enumerate ( ) {
18901891 last_pos = line_pos;
18911892 debug ! ( %line_pos, %line, ?highlight_parts) ;
@@ -1895,6 +1896,12 @@ impl EmitterWriter {
18951896 unhighlighted_lines. push ( ( line_pos, line) ) ;
18961897 continue ;
18971898 }
1899+ if highlight_parts. len ( ) == 1
1900+ && line. trim ( ) . starts_with ( "#[" )
1901+ && line. trim ( ) . ends_with ( ']' )
1902+ {
1903+ is_item_attribute = true ;
1904+ }
18981905
18991906 match unhighlighted_lines. len ( ) {
19001907 0 => ( ) ,
@@ -1971,11 +1978,13 @@ impl EmitterWriter {
19711978 is_multiline,
19721979 )
19731980 }
1974- if let DisplaySuggestion :: Add = show_code_change {
1981+ if let DisplaySuggestion :: Add = show_code_change && is_item_attribute {
19751982 // The suggestion adds an entire line of code, ending on a newline, so we'll also
19761983 // print the *following* line, to provide context of what we're advicing people to
19771984 // do. Otherwise you would only see contextless code that can be confused for
19781985 // 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.
19791988 let file_lines = sm
19801989 . span_to_lines ( span. primary_span ( ) . unwrap ( ) . shrink_to_hi ( ) )
19811990 . expect ( "span_to_lines failed when emitting suggestion" ) ;
0 commit comments