mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-14 17:07:26 +00:00
Move TokenExpander to base_db and rename it
It's only used to break the dependency to proc_macro_api
This commit is contained in:
parent
0fd75c98ac
commit
798968e1e3
4 changed files with 12 additions and 12 deletions
|
@ -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<Subtree, ExpansionError>;
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ProcMacro {
|
||||
pub name: SmolStr,
|
||||
pub kind: ProcMacroKind,
|
||||
pub expander: Arc<dyn TokenExpander>,
|
||||
pub expander: Arc<dyn ProcMacroExpander>,
|
||||
}
|
||||
|
||||
impl Eq for ProcMacro {}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<dyn tt::TokenExpander> = Arc::new(ProcMacroProcessExpander {
|
||||
let expander = Arc::new(ProcMacroProcessExpander {
|
||||
process: self.process.clone(),
|
||||
name: name.clone(),
|
||||
dylib_path: dylib_path.into(),
|
||||
|
|
|
@ -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<Subtree, ExpansionError>;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue