@@ -10,7 +10,7 @@ use cfg::{CfgExpr, CfgOptions};
1010use either:: Either ;
1111use hir_expand:: {
1212 attrs:: { Attr , AttrId } ,
13- builtin_attr_macro:: { find_builtin_attr, BuiltinAttrExpander } ,
13+ builtin_attr_macro:: find_builtin_attr,
1414 builtin_derive_macro:: find_builtin_derive,
1515 builtin_fn_macro:: find_builtin_macro,
1616 name:: { name, AsName , Name } ,
@@ -270,6 +270,7 @@ struct DefCollector<'a> {
270270 ///
271271 /// This also stores the attributes to skip when we resolve derive helpers and non-macro
272272 /// non-builtin attributes in general.
273+ // FIXME: There has to be a better way to do this
273274 skip_attrs : FxHashMap < InFile < ModItem > , AttrId > ,
274275}
275276
@@ -1255,17 +1256,23 @@ impl DefCollector<'_> {
12551256 _ => return Resolved :: No ,
12561257 } ;
12571258
1258- let call_id =
1259- attr_macro_as_call_id ( self . db , file_ast_id, attr, self . def_map . krate , def) ;
1260- if let MacroDefId {
1261- kind :
1262- MacroDefKind :: BuiltInAttr (
1263- BuiltinAttrExpander :: Derive | BuiltinAttrExpander :: DeriveConst ,
1264- _,
1265- ) ,
1266- ..
1267- } = def
1268- {
1259+ // Skip #[test]/#[bench] expansion, which would merely result in more memory usage
1260+ // due to duplicating functions into macro expansions
1261+ if matches ! (
1262+ def. kind,
1263+ MacroDefKind :: BuiltInAttr ( _, expander)
1264+ if expander. is_test( ) || expander. is_bench( )
1265+ ) {
1266+ return recollect_without ( self ) ;
1267+ }
1268+
1269+ let call_id = || {
1270+ attr_macro_as_call_id ( self . db , file_ast_id, attr, self . def_map . krate , def)
1271+ } ;
1272+ if matches ! ( def,
1273+ MacroDefId { kind: MacroDefKind :: BuiltInAttr ( _, exp) , .. }
1274+ if exp. is_derive( )
1275+ ) {
12691276 // Resolved to `#[derive]`, we don't actually expand this attribute like
12701277 // normal (as that would just be an identity expansion with extra output)
12711278 // Instead we treat derive attributes special and apply them separately.
@@ -1290,6 +1297,7 @@ impl DefCollector<'_> {
12901297
12911298 match attr. parse_path_comma_token_tree ( self . db . upcast ( ) ) {
12921299 Some ( derive_macros) => {
1300+ let call_id = call_id ( ) ;
12931301 let mut len = 0 ;
12941302 for ( idx, ( path, call_site) ) in derive_macros. enumerate ( ) {
12951303 let ast_id = AstIdWithPath :: new ( file_id, ast_id. value , path) ;
@@ -1312,13 +1320,6 @@ impl DefCollector<'_> {
13121320 // This is just a trick to be able to resolve the input to derives
13131321 // as proper paths in `Semantics`.
13141322 // Check the comment in [`builtin_attr_macro`].
1315- let call_id = attr_macro_as_call_id (
1316- self . db ,
1317- file_ast_id,
1318- attr,
1319- self . def_map . krate ,
1320- def,
1321- ) ;
13221323 self . def_map . modules [ directive. module_id ]
13231324 . scope
13241325 . init_derive_attribute ( ast_id, attr. id , call_id, len + 1 ) ;
@@ -1336,17 +1337,8 @@ impl DefCollector<'_> {
13361337 return recollect_without ( self ) ;
13371338 }
13381339
1339- // Skip #[test]/#[bench] expansion, which would merely result in more memory usage
1340- // due to duplicating functions into macro expansions
1341- if matches ! (
1342- def. kind,
1343- MacroDefKind :: BuiltInAttr ( expander, _)
1344- if expander. is_test( ) || expander. is_bench( )
1345- ) {
1346- return recollect_without ( self ) ;
1347- }
1348-
1349- if let MacroDefKind :: ProcMacro ( exp, ..) = def. kind {
1340+ let call_id = call_id ( ) ;
1341+ if let MacroDefKind :: ProcMacro ( _, exp, _) = def. kind {
13501342 // If proc attribute macro expansion is disabled, skip expanding it here
13511343 if !self . db . expand_proc_attr_macros ( ) {
13521344 self . def_map . diagnostics . push ( DefDiagnostic :: unresolved_proc_macro (
0 commit comments