internal: reduce coupling

tt is a data structure, data structures cant' go wrong, they shouldn't
have the knowledge that the world outside of them has all kinds of
errors.
This commit is contained in:
Aleksey Kladov 2021-08-31 19:14:33 +03:00
parent d8a3d6f378
commit 81602f8a5d
6 changed files with 25 additions and 32 deletions

View file

@ -1,7 +1,7 @@
//! Proc Macro Expander stub
use crate::db::AstDatabase;
use base_db::{CrateId, ProcMacroId};
use base_db::{CrateId, ProcMacroExpansionError, ProcMacroId};
use mbe::ExpandResult;
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
@ -42,7 +42,14 @@ impl ProcMacroExpander {
// Proc macros have access to the environment variables of the invoking crate.
let env = &krate_graph[calling_crate].env;
proc_macro.expander.expand(tt, attr_arg, env).map_err(mbe::ExpandError::from).into()
proc_macro
.expander
.expand(tt, attr_arg, env)
.map_err(|err| match err {
ProcMacroExpansionError::Panic(text) => mbe::ExpandError::Other(text),
ProcMacroExpansionError::System(text) => mbe::ExpandError::Other(text),
})
.into()
}
None => ExpandResult::only_err(mbe::ExpandError::UnresolvedProcMacro),
}