@@ -206,6 +206,7 @@ fn traverse(
206
206
207
207
let mut current_macro_call: Option < ast:: MacroCall > = None ;
208
208
let mut current_attr_call = None ;
209
+ let mut current_derive_call = None ;
209
210
let mut current_macro: Option < ast:: Macro > = None ;
210
211
let mut macro_highlighter = MacroHighlighter :: default ( ) ;
211
212
let mut inside_attribute = false ;
@@ -249,7 +250,7 @@ fn traverse(
249
250
} ;
250
251
match adt {
251
252
Some ( adt) if sema. is_derive_annotated ( & adt) => {
252
- current_attr_call = Some ( adt . into ( ) ) ;
253
+ current_derive_call = Some ( ast :: Item :: from ( adt ) ) ;
253
254
}
254
255
_ => ( ) ,
255
256
}
@@ -273,7 +274,10 @@ fn traverse(
273
274
macro_highlighter = MacroHighlighter :: default ( ) ;
274
275
}
275
276
Some ( item) if current_attr_call. as_ref ( ) . map_or ( false , |it| * it == item) => {
276
- current_attr_call = None
277
+ current_attr_call = None ;
278
+ }
279
+ Some ( item) if current_derive_call. as_ref ( ) . map_or ( false , |it| * it == item) => {
280
+ current_derive_call = None ;
277
281
}
278
282
None if ast:: Attr :: can_cast ( node. kind ( ) ) => inside_attribute = false ,
279
283
_ => ( ) ,
@@ -301,17 +305,19 @@ fn traverse(
301
305
// as calling `descend_into_macros_single` gets rather expensive if done for every single token
302
306
// additionally, do not descend into comments, descending maps down to doc attributes which get
303
307
// tagged as string literals.
304
- let descend_token = ( current_macro_call. is_some ( ) || current_attr_call. is_some ( ) )
308
+ let descend_token = ( current_macro_call. is_some ( )
309
+ || current_attr_call. is_some ( )
310
+ || current_derive_call. is_some ( ) )
305
311
&& element. kind ( ) != COMMENT ;
306
312
let element_to_highlight = if descend_token {
307
313
let token = match & element {
308
314
NodeOrToken :: Node ( _) => continue ,
309
315
NodeOrToken :: Token ( tok) => tok. clone ( ) ,
310
316
} ;
311
- let in_mcall_outside_tt = current_macro_call . is_some ( )
317
+ let in_mcall_outside_tt = current_attr_call . is_none ( )
312
318
&& token. parent ( ) . as_ref ( ) . map ( SyntaxNode :: kind) != Some ( TOKEN_TREE ) ;
313
319
let token = match in_mcall_outside_tt {
314
- // not in the macros token tree, don't attempt to descend
320
+ // not in the macros/derives token tree, don't attempt to descend
315
321
true => token,
316
322
false => sema. descend_into_macros_single ( token) ,
317
323
} ;
0 commit comments