@@ -476,12 +476,12 @@ impl<'db> SemanticsImpl<'db> {
476
476
}
477
477
478
478
fn derive_macro_calls ( & self , attr : & ast:: Attr ) -> Option < Vec < Option < MacroCallId > > > {
479
- let item = attr. syntax ( ) . parent ( ) . and_then ( ast:: Item :: cast) ?;
480
- let file_id = self . find_file ( item . syntax ( ) ) . file_id ;
481
- let item = InFile :: new ( file_id, & item ) ;
479
+ let adt = attr. syntax ( ) . parent ( ) . and_then ( ast:: Adt :: cast) ?;
480
+ let file_id = self . find_file ( adt . syntax ( ) ) . file_id ;
481
+ let adt = InFile :: new ( file_id, & adt ) ;
482
482
let src = InFile :: new ( file_id, attr. clone ( ) ) ;
483
483
self . with_ctx ( |ctx| {
484
- let res = ctx. attr_to_derive_macro_call ( item , src) ?;
484
+ let res = ctx. attr_to_derive_macro_call ( adt , src) ?;
485
485
Some ( res. to_vec ( ) )
486
486
} )
487
487
}
@@ -909,17 +909,8 @@ impl<'db> SemanticsImpl<'db> {
909
909
return None ;
910
910
}
911
911
912
- // Fetch hir::Attr definition
913
- // FIXME: Move this to ToDef impl?
914
- let adt = attr. syntax ( ) . parent ( ) . and_then ( ast:: Adt :: cast) ?;
915
- let attr_pos = adt. attrs ( ) . position ( |it| it == attr) ?;
916
- let attrs = {
917
- let file_id = self . find_file ( adt. syntax ( ) ) . file_id ;
918
- let adt = InFile :: new ( file_id, adt) ;
919
- let def = self . with_ctx ( |ctx| ctx. adt_to_def ( adt) ) ?;
920
- self . db . attrs ( def. into ( ) )
921
- } ;
922
- let attr_def = attrs. get ( attr_pos) ?;
912
+ let attr_def =
913
+ ast:: Attr :: to_def ( self , self . find_file ( attr. syntax ( ) ) . with_value ( attr. clone ( ) ) ) ?;
923
914
924
915
let mut derive_paths = attr_def. parse_path_comma_token_tree ( ) ?;
925
916
let derives = self . resolve_derive_macro ( & attr) ?;
@@ -1214,6 +1205,7 @@ to_def_impls![
1214
1205
( crate :: Local , ast:: SelfParam , self_param_to_def) ,
1215
1206
( crate :: Label , ast:: Label , label_to_def) ,
1216
1207
( crate :: Adt , ast:: Adt , adt_to_def) ,
1208
+ ( crate :: Attr , ast:: Attr , attr_to_def) ,
1217
1209
] ;
1218
1210
1219
1211
fn find_root ( node : & SyntaxNode ) -> SyntaxNode {
0 commit comments