@@ -4,6 +4,8 @@ use span::{MacroCallId, Span};
44
55use crate :: { db:: ExpandDatabase , name, tt, ExpandResult , MacroCallKind } ;
66
7+ use super :: quote;
8+
79macro_rules! register_builtin {
810 ( $( ( $name: ident, $variant: ident) => $expand: ident) ,* ) => {
911 #[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash ) ]
@@ -52,15 +54,15 @@ impl BuiltinAttrExpander {
5254}
5355
5456register_builtin ! {
55- ( bench, Bench ) => dummy_attr_expand ,
57+ ( bench, Bench ) => dummy_gate_test_expand ,
5658 ( cfg_accessible, CfgAccessible ) => dummy_attr_expand,
5759 ( cfg_eval, CfgEval ) => dummy_attr_expand,
5860 ( derive, Derive ) => derive_expand,
5961 // derive const is equivalent to derive for our proposes.
6062 ( derive_const, DeriveConst ) => derive_expand,
6163 ( global_allocator, GlobalAllocator ) => dummy_attr_expand,
62- ( test, Test ) => dummy_attr_expand ,
63- ( test_case, TestCase ) => dummy_attr_expand
64+ ( test, Test ) => dummy_gate_test_expand ,
65+ ( test_case, TestCase ) => dummy_gate_test_expand
6466}
6567
6668pub fn find_builtin_attr ( ident : & name:: Name ) -> Option < BuiltinAttrExpander > {
@@ -76,6 +78,19 @@ fn dummy_attr_expand(
7678 ExpandResult :: ok ( tt. clone ( ) )
7779}
7880
81+ fn dummy_gate_test_expand (
82+ _db : & dyn ExpandDatabase ,
83+ _id : MacroCallId ,
84+ tt : & tt:: Subtree ,
85+ span : Span ,
86+ ) -> ExpandResult < tt:: Subtree > {
87+ let result = quote:: quote! { span=>
88+ #[ cfg( test) ]
89+ #tt
90+ } ;
91+ ExpandResult :: ok ( result)
92+ }
93+
7994/// We generate a very specific expansion here, as we do not actually expand the `#[derive]` attribute
8095/// itself in name res, but we do want to expand it to something for the IDE layer, so that the input
8196/// derive attributes can be downmapped, and resolved as proper paths.
0 commit comments