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), )*
40 (bench, Bench) => dummy_attr_expand,
41 (cfg_accessible, CfgAccessible) => dummy_attr_expand,
42 (cfg_eval, CfgEval) => dummy_attr_expand,
43 (derive, Derive) => dummy_attr_expand,
44 (global_allocator, GlobalAllocator) => dummy_attr_expand,
45 (test, Test) => dummy_attr_expand,
46 (test_case, TestCase) => dummy_attr_expand
49 pub fn find_builtin_attr(
52 ast_id: AstId<ast::Macro>,
53 ) -> Option<MacroDefId> {
54 let expander = BuiltinAttrExpander::find_by_name(ident)?;
57 kind: MacroDefKind::BuiltInAttr(expander, ast_id),
63 _db: &dyn AstDatabase,
66 ) -> ExpandResult<tt::Subtree> {
67 ExpandResult::ok(tt.clone())