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 +- crates/proc_macro_api/src/lib.rs | 4 ++-- crates/tt/src/lib.rs | 7 +------ 4 files changed, 12 insertions(+), 12 deletions(-) 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; diff --git a/crates/proc_macro_api/src/lib.rs b/crates/proc_macro_api/src/lib.rs index 0d061fd53..a61afbbd6 100644 --- a/crates/proc_macro_api/src/lib.rs +++ b/crates/proc_macro_api/src/lib.rs @@ -39,7 +39,7 @@ impl PartialEq for ProcMacroProcessExpander { } } -impl tt::TokenExpander for ProcMacroProcessExpander { +impl base_db::ProcMacroExpander for ProcMacroProcessExpander { fn expand( &self, subtree: &Subtree, @@ -90,7 +90,7 @@ impl ProcMacroClient { ProcMacroKind::FuncLike => base_db::ProcMacroKind::FuncLike, ProcMacroKind::Attr => base_db::ProcMacroKind::Attr, }; - let expander: Arc = Arc::new(ProcMacroProcessExpander { + let expander = Arc::new(ProcMacroProcessExpander { process: self.process.clone(), name: name.clone(), dylib_path: dylib_path.into(), diff --git a/crates/tt/src/lib.rs b/crates/tt/src/lib.rs index 6c1bf8d09..8301dc28a 100644 --- a/crates/tt/src/lib.rs +++ b/crates/tt/src/lib.rs @@ -1,7 +1,7 @@ //! `tt` crate defines a `TokenTree` data structure: this is the interface (both //! input and output) of macros. It closely mirrors `proc_macro` crate's //! `TokenTree`. -use std::{fmt, panic::RefUnwindSafe}; +use std::fmt; use stdx::impl_from; @@ -247,8 +247,3 @@ impl fmt::Display for ExpansionError { } } } - -pub trait TokenExpander: fmt::Debug + Send + Sync + RefUnwindSafe { - fn expand(&self, subtree: &Subtree, attrs: Option<&Subtree>) - -> Result; -} -- cgit v1.2.3