Skip to content

Commit 798968e

Browse files
Move TokenExpander to base_db and rename it
It's only used to break the dependency to proc_macro_api
1 parent 0fd75c9 commit 798968e

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

crates/base_db/src/input.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
//! actual IO. See `vfs` and `project_model` in the `rust-analyzer` crate for how
77
//! actual IO is done and lowered to input.
88
9-
use std::{fmt, iter::FromIterator, ops, str::FromStr, sync::Arc};
9+
use std::{fmt, iter::FromIterator, ops, panic::RefUnwindSafe, str::FromStr, sync::Arc};
1010

1111
use cfg::CfgOptions;
1212
use rustc_hash::{FxHashMap, FxHashSet};
1313
use syntax::SmolStr;
14-
use tt::TokenExpander;
14+
use tt::{ExpansionError, Subtree};
1515
use vfs::{file_set::FileSet, FileId, VfsPath};
1616

1717
/// Files are grouped into source roots. A source root is a directory on the
@@ -150,11 +150,16 @@ pub enum ProcMacroKind {
150150
Attr,
151151
}
152152

153+
pub trait ProcMacroExpander: fmt::Debug + Send + Sync + RefUnwindSafe {
154+
fn expand(&self, subtree: &Subtree, attrs: Option<&Subtree>)
155+
-> Result<Subtree, ExpansionError>;
156+
}
157+
153158
#[derive(Debug, Clone)]
154159
pub struct ProcMacro {
155160
pub name: SmolStr,
156161
pub kind: ProcMacroKind,
157-
pub expander: Arc<dyn TokenExpander>,
162+
pub expander: Arc<dyn ProcMacroExpander>,
158163
}
159164

160165
impl Eq for ProcMacro {}

crates/base_db/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub use crate::{
1414
change::Change,
1515
input::{
1616
CrateData, CrateDisplayName, CrateGraph, CrateId, CrateName, Dependency, Edition, Env,
17-
ProcMacro, ProcMacroId, ProcMacroKind, SourceRoot, SourceRootId,
17+
ProcMacro, ProcMacroExpander, ProcMacroId, ProcMacroKind, SourceRoot, SourceRootId,
1818
},
1919
};
2020
pub use salsa;

crates/proc_macro_api/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl PartialEq for ProcMacroProcessExpander {
3939
}
4040
}
4141

42-
impl tt::TokenExpander for ProcMacroProcessExpander {
42+
impl base_db::ProcMacroExpander for ProcMacroProcessExpander {
4343
fn expand(
4444
&self,
4545
subtree: &Subtree,
@@ -90,7 +90,7 @@ impl ProcMacroClient {
9090
ProcMacroKind::FuncLike => base_db::ProcMacroKind::FuncLike,
9191
ProcMacroKind::Attr => base_db::ProcMacroKind::Attr,
9292
};
93-
let expander: Arc<dyn tt::TokenExpander> = Arc::new(ProcMacroProcessExpander {
93+
let expander = Arc::new(ProcMacroProcessExpander {
9494
process: self.process.clone(),
9595
name: name.clone(),
9696
dylib_path: dylib_path.into(),

crates/tt/src/lib.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! `tt` crate defines a `TokenTree` data structure: this is the interface (both
22
//! input and output) of macros. It closely mirrors `proc_macro` crate's
33
//! `TokenTree`.
4-
use std::{fmt, panic::RefUnwindSafe};
4+
use std::fmt;
55

66
use stdx::impl_from;
77

@@ -247,8 +247,3 @@ impl fmt::Display for ExpansionError {
247247
}
248248
}
249249
}
250-
251-
pub trait TokenExpander: fmt::Debug + Send + Sync + RefUnwindSafe {
252-
fn expand(&self, subtree: &Subtree, attrs: Option<&Subtree>)
253-
-> Result<Subtree, ExpansionError>;
254-
}

0 commit comments

Comments
 (0)