@@ -356,8 +356,12 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
356
356
self . imp . resolve_bind_pat_to_const ( pat)
357
357
}
358
358
359
- pub fn resolve_derive_ident ( & self , ident : & ast:: Ident ) -> Option < PathResolution > {
360
- self . imp . resolve_derive_ident ( ident)
359
+ pub fn resolve_derive_ident (
360
+ & self ,
361
+ derive : & ast:: Attr ,
362
+ ident : & ast:: Ident ,
363
+ ) -> Option < PathResolution > {
364
+ self . imp . resolve_derive_ident ( derive, ident)
361
365
}
362
366
363
367
// FIXME: use this instead?
@@ -900,23 +904,26 @@ impl<'db> SemanticsImpl<'db> {
900
904
self . analyze ( pat. syntax ( ) ) . resolve_bind_pat_to_const ( self . db , pat)
901
905
}
902
906
903
- fn resolve_derive_ident ( & self , ident : & ast:: Ident ) -> Option < PathResolution > {
907
+ fn resolve_derive_ident (
908
+ & self ,
909
+ derive : & ast:: Attr ,
910
+ ident : & ast:: Ident ,
911
+ ) -> Option < PathResolution > {
912
+ debug_assert ! ( ident. syntax( ) . parent( ) . and_then( ast:: TokenTree :: cast) . is_some( ) ) ;
913
+ debug_assert ! ( ident. syntax( ) . ancestors( ) . any( |anc| anc == * derive. syntax( ) ) ) ;
904
914
// derive macros are always at depth 2, tokentree -> meta -> attribute
905
915
let syntax = ident. syntax ( ) ;
906
- let attr = syntax. ancestors ( ) . nth ( 2 ) . and_then ( ast:: Attr :: cast) ?;
907
916
908
- let tt = attr. token_tree ( ) ?;
909
- if !tt. syntax ( ) . text_range ( ) . contains_range ( ident. syntax ( ) . text_range ( ) ) {
910
- return None ;
911
- }
912
-
913
- let file = self . find_file ( attr. syntax ( ) ) ;
914
- let adt = attr. syntax ( ) . parent ( ) . and_then ( ast:: Adt :: cast) ?;
917
+ let tt = derive. token_tree ( ) ?;
918
+ let file = self . find_file ( derive. syntax ( ) ) ;
919
+ let adt = derive. syntax ( ) . parent ( ) . and_then ( ast:: Adt :: cast) ?;
915
920
916
921
let res = self . with_ctx ( |ctx| {
917
- let attr_def = ctx. attr_to_def ( file. with_value ( attr. clone ( ) ) ) ?;
918
- let derives = ctx
919
- . attr_to_derive_macro_call ( file. with_value ( & adt) , file. with_value ( attr. clone ( ) ) ) ?;
922
+ let attr_def = ctx. attr_to_def ( file. with_value ( derive. clone ( ) ) ) ?;
923
+ let derives = ctx. attr_to_derive_macro_call (
924
+ file. with_value ( & adt) ,
925
+ file. with_value ( derive. clone ( ) ) ,
926
+ ) ?;
920
927
921
928
let mut derive_paths = attr_def. parse_path_comma_token_tree ( ) ?;
922
929
@@ -951,7 +958,7 @@ impl<'db> SemanticsImpl<'db> {
951
958
match res {
952
959
Either :: Left ( path) => resolve_hir_path (
953
960
self . db ,
954
- & self . scope ( attr . syntax ( ) ) . resolver ,
961
+ & self . scope ( derive . syntax ( ) ) . resolver ,
955
962
& Path :: from_known_path ( path, [ ] ) ,
956
963
)
957
964
. filter ( |res| matches ! ( res, PathResolution :: Def ( ModuleDef :: Module ( _) ) ) ) ,
0 commit comments