1 //! Builtin attributes.
6 use crate::{db::AstDatabase, name, AstId, CrateId, MacroCallId, MacroDefId, MacroDefKind};
8 macro_rules! register_builtin {
9 ( $(($name:ident, $variant:ident) => $expand:ident),* ) => {
10 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
11 pub enum BuiltinAttrExpander {
15 impl BuiltinAttrExpander {
21 ) -> ExpandResult<tt::Subtree> {
22 let expander = match *self {
23 $( BuiltinAttrExpander::$variant => $expand, )*
28 fn find_by_name(name: &name::Name) -> Option<Self> {
30 $( id if id == &name::name![$name] => Some(BuiltinAttrExpander::$variant), )*
39 impl BuiltinAttrExpander {
40 pub fn is_derive(self) -> bool {
41 matches!(self, BuiltinAttrExpander::Derive)
43 pub fn is_test(self) -> bool {
44 matches!(self, BuiltinAttrExpander::Test)
46 pub fn is_bench(self) -> bool {
47 matches!(self, BuiltinAttrExpander::Bench)
52 (bench, Bench) => dummy_attr_expand,
53 (cfg_accessible, CfgAccessible) => dummy_attr_expand,
54 (cfg_eval, CfgEval) => dummy_attr_expand,
55 (derive, Derive) => dummy_attr_expand,
56 (global_allocator, GlobalAllocator) => dummy_attr_expand,
57 (test, Test) => dummy_attr_expand,
58 (test_case, TestCase) => dummy_attr_expand
61 pub fn find_builtin_attr(
64 ast_id: AstId<ast::Macro>,
65 ) -> Option<MacroDefId> {
66 let expander = BuiltinAttrExpander::find_by_name(ident)?;
69 kind: MacroDefKind::BuiltInAttr(expander, ast_id),
75 _db: &dyn AstDatabase,
78 ) -> ExpandResult<tt::Subtree> {
79 ExpandResult::ok(tt.clone())