1 //! Builtin attributes.
6 db::AstDatabase, name, AstId, CrateId, ExpandResult, MacroCallId, MacroDefId, MacroDefKind,
9 macro_rules! register_builtin {
10 ( $(($name:ident, $variant:ident) => $expand:ident),* ) => {
11 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
12 pub enum BuiltinAttrExpander {
16 impl BuiltinAttrExpander {
22 ) -> ExpandResult<tt::Subtree> {
23 let expander = match *self {
24 $( BuiltinAttrExpander::$variant => $expand, )*
29 fn find_by_name(name: &name::Name) -> Option<Self> {
31 $( id if id == &name::name![$name] => Some(BuiltinAttrExpander::$variant), )*
40 impl BuiltinAttrExpander {
41 pub fn is_derive(self) -> bool {
42 matches!(self, BuiltinAttrExpander::Derive)
44 pub fn is_test(self) -> bool {
45 matches!(self, BuiltinAttrExpander::Test)
47 pub fn is_bench(self) -> bool {
48 matches!(self, BuiltinAttrExpander::Bench)
53 (bench, Bench) => dummy_attr_expand,
54 (cfg_accessible, CfgAccessible) => dummy_attr_expand,
55 (cfg_eval, CfgEval) => dummy_attr_expand,
56 (derive, Derive) => dummy_attr_expand,
57 (global_allocator, GlobalAllocator) => dummy_attr_expand,
58 (test, Test) => dummy_attr_expand,
59 (test_case, TestCase) => dummy_attr_expand
62 pub fn find_builtin_attr(
65 ast_id: AstId<ast::Macro>,
66 ) -> Option<MacroDefId> {
67 let expander = BuiltinAttrExpander::find_by_name(ident)?;
70 kind: MacroDefKind::BuiltInAttr(expander, ast_id),
76 _db: &dyn AstDatabase,
79 ) -> ExpandResult<tt::Subtree> {
80 ExpandResult::ok(tt.clone())