diff options
author | Jonas Schievink <[email protected]> | 2020-12-11 13:24:02 +0000 |
---|---|---|
committer | Jonas Schievink <[email protected]> | 2020-12-27 14:29:47 +0000 |
commit | 798968e1e3a7d9eafa0c27c857571cdc347c34a7 (patch) | |
tree | 79e82b07d8486f2d9b710706e5aacc07f25ddbb9 /crates | |
parent | 0fd75c98ac81c9f6581712ec8802940e547315e3 (diff) |
Move TokenExpander to base_db and rename it
It's only used to break the dependency to proc_macro_api
Diffstat (limited to 'crates')
-rw-r--r-- | crates/base_db/src/input.rs | 11 | ||||
-rw-r--r-- | crates/base_db/src/lib.rs | 2 | ||||
-rw-r--r-- | crates/proc_macro_api/src/lib.rs | 4 | ||||
-rw-r--r-- | 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 @@ | |||
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 | ||
9 | use std::{fmt, iter::FromIterator, ops, str::FromStr, sync::Arc}; | 9 | use std::{fmt, iter::FromIterator, ops, panic::RefUnwindSafe, str::FromStr, sync::Arc}; |
10 | 10 | ||
11 | use cfg::CfgOptions; | 11 | use cfg::CfgOptions; |
12 | use rustc_hash::{FxHashMap, FxHashSet}; | 12 | use rustc_hash::{FxHashMap, FxHashSet}; |
13 | use syntax::SmolStr; | 13 | use syntax::SmolStr; |
14 | use tt::TokenExpander; | 14 | use tt::{ExpansionError, Subtree}; |
15 | use vfs::{file_set::FileSet, FileId, VfsPath}; | 15 | use 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 | ||
153 | pub 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)] |
154 | pub struct ProcMacro { | 159 | pub 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 | ||
160 | impl Eq for ProcMacro {} | 165 | 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::{ | |||
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 | }; |
20 | pub use salsa; | 20 | 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 { | |||
39 | } | 39 | } |
40 | } | 40 | } |
41 | 41 | ||
42 | impl tt::TokenExpander for ProcMacroProcessExpander { | 42 | impl 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`. |
4 | use std::{fmt, panic::RefUnwindSafe}; | 4 | use std::fmt; |
5 | 5 | ||
6 | use stdx::impl_from; | 6 | use stdx::impl_from; |
7 | 7 | ||
@@ -247,8 +247,3 @@ impl fmt::Display for ExpansionError { | |||
247 | } | 247 | } |
248 | } | 248 | } |
249 | } | 249 | } |
250 | |||
251 | pub trait TokenExpander: fmt::Debug + Send + Sync + RefUnwindSafe { | ||
252 | fn expand(&self, subtree: &Subtree, attrs: Option<&Subtree>) | ||
253 | -> Result<Subtree, ExpansionError>; | ||
254 | } | ||