aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonas Schievink <[email protected]>2020-12-11 13:24:02 +0000
committerJonas Schievink <[email protected]>2020-12-27 14:29:47 +0000
commit798968e1e3a7d9eafa0c27c857571cdc347c34a7 (patch)
tree79e82b07d8486f2d9b710706e5aacc07f25ddbb9
parent0fd75c98ac81c9f6581712ec8802940e547315e3 (diff)
Move TokenExpander to base_db and rename it
It's only used to break the dependency to proc_macro_api
-rw-r--r--crates/base_db/src/input.rs11
-rw-r--r--crates/base_db/src/lib.rs2
-rw-r--r--crates/proc_macro_api/src/lib.rs4
-rw-r--r--crates/tt/src/lib.rs7
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 @@
6//! actual IO. See `vfs` and `project_model` in the `rust-analyzer` crate for how 6//! actual IO. See `vfs` and `project_model` in the `rust-analyzer` crate for how
7//! actual IO is done and lowered to input. 7//! actual IO is done and lowered to input.
8 8
9use std::{fmt, iter::FromIterator, ops, str::FromStr, sync::Arc}; 9use std::{fmt, iter::FromIterator, ops, panic::RefUnwindSafe, str::FromStr, sync::Arc};
10 10
11use cfg::CfgOptions; 11use cfg::CfgOptions;
12use rustc_hash::{FxHashMap, FxHashSet}; 12use rustc_hash::{FxHashMap, FxHashSet};
13use syntax::SmolStr; 13use syntax::SmolStr;
14use tt::TokenExpander; 14use tt::{ExpansionError, Subtree};
15use vfs::{file_set::FileSet, FileId, VfsPath}; 15use vfs::{file_set::FileSet, FileId, VfsPath};
16 16
17/// Files are grouped into source roots. A source root is a directory on the 17/// Files are grouped into source roots. A source root is a directory on the
@@ -150,11 +150,16 @@ pub enum ProcMacroKind {
150 Attr, 150 Attr,
151} 151}
152 152
153pub trait ProcMacroExpander: fmt::Debug + Send + Sync + RefUnwindSafe {
154 fn expand(&self, subtree: &Subtree, attrs: Option<&Subtree>)
155 -> Result<Subtree, ExpansionError>;
156}
157
153#[derive(Debug, Clone)] 158#[derive(Debug, Clone)]
154pub struct ProcMacro { 159pub struct ProcMacro {
155 pub name: SmolStr, 160 pub name: SmolStr,
156 pub kind: ProcMacroKind, 161 pub kind: ProcMacroKind,
157 pub expander: Arc<dyn TokenExpander>, 162 pub expander: Arc<dyn ProcMacroExpander>,
158} 163}
159 164
160impl Eq for ProcMacro {} 165impl 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::{
14 change::Change, 14 change::Change,
15 input::{ 15 input::{
16 CrateData, CrateDisplayName, CrateGraph, CrateId, CrateName, Dependency, Edition, Env, 16 CrateData, CrateDisplayName, CrateGraph, CrateId, CrateName, Dependency, Edition, Env,
17 ProcMacro, ProcMacroId, ProcMacroKind, SourceRoot, SourceRootId, 17 ProcMacro, ProcMacroExpander, ProcMacroId, ProcMacroKind, SourceRoot, SourceRootId,
18 }, 18 },
19}; 19};
20pub use salsa; 20pub 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 {
39 } 39 }
40} 40}
41 41
42impl tt::TokenExpander for ProcMacroProcessExpander { 42impl base_db::ProcMacroExpander for ProcMacroProcessExpander {
43 fn expand( 43 fn expand(
44 &self, 44 &self,
45 subtree: &Subtree, 45 subtree: &Subtree,
@@ -90,7 +90,7 @@ impl ProcMacroClient {
90 ProcMacroKind::FuncLike => base_db::ProcMacroKind::FuncLike, 90 ProcMacroKind::FuncLike => base_db::ProcMacroKind::FuncLike,
91 ProcMacroKind::Attr => base_db::ProcMacroKind::Attr, 91 ProcMacroKind::Attr => base_db::ProcMacroKind::Attr,
92 }; 92 };
93 let expander: Arc<dyn tt::TokenExpander> = Arc::new(ProcMacroProcessExpander { 93 let expander = Arc::new(ProcMacroProcessExpander {
94 process: self.process.clone(), 94 process: self.process.clone(),
95 name: name.clone(), 95 name: name.clone(),
96 dylib_path: dylib_path.into(), 96 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 @@
1//! `tt` crate defines a `TokenTree` data structure: this is the interface (both 1//! `tt` crate defines a `TokenTree` data structure: this is the interface (both
2//! input and output) of macros. It closely mirrors `proc_macro` crate's 2//! input and output) of macros. It closely mirrors `proc_macro` crate's
3//! `TokenTree`. 3//! `TokenTree`.
4use std::{fmt, panic::RefUnwindSafe}; 4use std::fmt;
5 5
6use stdx::impl_from; 6use stdx::impl_from;
7 7
@@ -247,8 +247,3 @@ impl fmt::Display for ExpansionError {
247 } 247 }
248 } 248 }
249} 249}
250
251pub trait TokenExpander: fmt::Debug + Send + Sync + RefUnwindSafe {
252 fn expand(&self, subtree: &Subtree, attrs: Option<&Subtree>)
253 -> Result<Subtree, ExpansionError>;
254}