1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63//! When specifying SSR rule, you generally want to map one *kind* of thing to //! the same kind of thing: path to path, expression to expression, type to //! type. //! //! The problem is, while this *kind* is generally obvious to the human, the ide //! needs to determine it somehow. We do this in a stupid way -- by pasting SSR //! rule into different contexts and checking what works. use syntax::{AstNode, SyntaxNode, ast}; pub(crate) fn ty(s: &str) -> Result<SyntaxNode, ()> { fragment::<ast::Type>("type T = {};", s) } pub(crate) fn item(s: &str) -> Result<SyntaxNode, ()> { fragment::<ast::Item>("{}", s) } pub(crate) fn pat(s: &str) -> Result<SyntaxNode, ()> { fragment::<ast::Pat>("const _: () = {let {} = ();};", s) } pub(crate) fn expr(s: &str) -> Result<SyntaxNode, ()> { fragment::<ast::Expr>("const _: () = {};", s) } pub(crate) fn stmt(s: &str) -> Result<SyntaxNode, ()> { let template = "const _: () = { {}; };"; let input = template.replace("{}", s); let parse = syntax::SourceFile::parse(&input, syntax::Edition::CURRENT); if !parse.errors().is_empty() { return Err(()); } let mut node = //! Nameres-specific procedural macro data and helpers. use hir_expand::name::{AsName, Name}; use intern::sym; use crate::attr::Attrs; use crate::tt::{Leaf, TokenTree, TopSubtree, TtElement}; #[derive(Debug, PartialEq, Eq)] pub struct ProcMacroDef { pub name: Name, pub kind: ProcMacroKind, } #[derive(Debug, PartialEq, Eq)] pub enum ProcMacroKind { Derive { helpers: Box<[Name]> }, Bang, Attr, } impl ProcMacroKind { pub(super) fn to_basedb_kind(&self) -> hir_expand::proc_macro::ProcMacroKind { match self { ProcMacroKind::Derive { .. } => hir_expand::proc_macro::ProcMacroKind::CustomDerive, ProcMacroKind::Bang => hir_expand::proc_macro::ProcMacroKind::Bang, ProcMacroKind::Attr => hir_expand::proc_macro::ProcMacroKind::Attr, } } } impl Attrs { pub fn parse_proc_macro_decl(&self, func_name: &Nam