From 798968e1e3a7d9eafa0c27c857571cdc347c34a7 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Fri, 11 Dec 2020 14:24:02 +0100 Subject: Move TokenExpander to base_db and rename it It's only used to break the dependency to proc_macro_api --- crates/base_db/src/input.rs | 11 ++++++++--- crates/base_db/src/lib.rs | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) (limited to 'crates/base_db/src') diff --git a/crates/base_db/src/input.rs b/crates/base_db/src/input.rs index cda5e57dc..a693e7f80 100644 --- a/crates/base_db/src/input.rs +++ b/crates/base_db/src/input.rs @@ -6,12 +6,12 @@ //! actual IO. See `vfs` and `project_model` in the `rust-analyzer` crate for how //! actual IO is done and lowered to input. -use std::{fmt, iter::FromIterator, ops, str::FromStr, sync::Arc}; +use std::{fmt, iter::FromIterator, ops, panic::RefUnwindSafe, str::FromStr, sync::Arc}; use cfg::CfgOptions; use rustc_hash::{FxHashMap, FxHashSet}; use syntax::SmolStr; -use tt::TokenExpander; +use tt::{ExpansionError, Subtree}; use vfs::{file_set::FileSet, FileId, VfsPath}; /// Files are grouped into source roots. A source root is a directory on the @@ -150,11 +150,16 @@ pub enum ProcMacroKind { Attr, } +pub trait ProcMacroExpander: fmt::Debug + Send + Sync + RefUnwindSafe { + fn expand(&self, subtree: &Subtree, attrs: Option<&Subtree>) + -> Result; +} + #[derive(Debug, Clone)] pub struct ProcMacro { pub name: SmolStr, pub kind: ProcMacroKind, - pub expander: Arc, + pub expander: Arc, } impl Eq for ProcMacro {} diff --git a/crates/base_db/src/lib.rs b/crates/base_db/src/lib.rs index 595f28ada..5f77a0b1f 100644 --- a/crates/base_db/src/lib.rs +++ b/crates/base_db/src/lib.rs @@ -14,7 +14,7 @@ pub use crate::{ change::Change, input::{ CrateData, CrateDisplayName, CrateGraph, CrateId, CrateName, Dependency, Edition, Env, - ProcMacro, ProcMacroId, ProcMacroKind, SourceRoot, SourceRootId, + ProcMacro, ProcMacroExpander, ProcMacroId, ProcMacroKind, SourceRoot, SourceRootId, }, }; pub use salsa; -- cgit v1.2.3