@@ -4,6 +4,8 @@ use span::{MacroCallId, Span};
4
4
5
5
use crate :: { db:: ExpandDatabase , name, tt, ExpandResult , MacroCallKind } ;
6
6
7
+ use super :: quote;
8
+
7
9
macro_rules! register_builtin {
8
10
( $( ( $name: ident, $variant: ident) => $expand: ident) ,* ) => {
9
11
#[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash ) ]
@@ -52,15 +54,15 @@ impl BuiltinAttrExpander {
52
54
}
53
55
54
56
register_builtin ! {
55
- ( bench, Bench ) => dummy_attr_expand ,
57
+ ( bench, Bench ) => dummy_gate_test_expand ,
56
58
( cfg_accessible, CfgAccessible ) => dummy_attr_expand,
57
59
( cfg_eval, CfgEval ) => dummy_attr_expand,
58
60
( derive, Derive ) => derive_expand,
59
61
// derive const is equivalent to derive for our proposes.
60
62
( derive_const, DeriveConst ) => derive_expand,
61
63
( 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
64
66
}
65
67
66
68
pub fn find_builtin_attr ( ident : & name:: Name ) -> Option < BuiltinAttrExpander > {
@@ -76,6 +78,19 @@ fn dummy_attr_expand(
76
78
ExpandResult :: ok ( tt. clone ( ) )
77
79
}
78
80
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
+
79
94
/// We generate a very specific expansion here, as we do not actually expand the `#[derive]` attribute
80
95
/// itself in name res, but we do want to expand it to something for the IDE layer, so that the input
81
96
/// derive attributes can be downmapped, and resolved as proper paths.
0 commit comments