internal: Split unresolve proc-macro error out of mbe

This commit is contained in:
Lukas Wirth
2022-02-21 19:14:06 +01:00
parent b663b733d9
commit 1505b6a9b4
13 changed files with 147 additions and 104 deletions

View File

@@ -17,9 +17,9 @@ pub mod eager;
pub mod mod_path;
mod fixup;
pub use mbe::{ExpandError, ExpandResult, Origin};
pub use mbe::{Origin, ValueResult};
use std::{hash::Hash, iter, sync::Arc};
use std::{fmt, hash::Hash, iter, sync::Arc};
use base_db::{impl_intern_key, salsa, CrateId, FileId, FileRange, ProcMacroKind};
use either::Either;
@@ -39,6 +39,31 @@ use crate::{
proc_macro::ProcMacroExpander,
};
pub type ExpandResult<T> = ValueResult<T, ExpandError>;
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum ExpandError {
UnresolvedProcMacro,
Mbe(mbe::ExpandError),
Other(Box<str>),
}
impl From<mbe::ExpandError> for ExpandError {
fn from(mbe: mbe::ExpandError) -> Self {
Self::Mbe(mbe)
}
}
impl fmt::Display for ExpandError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
ExpandError::UnresolvedProcMacro => f.write_str("unresolved proc-macro"),
ExpandError::Mbe(it) => it.fmt(f),
ExpandError::Other(it) => f.write_str(it),
}
}
}
/// Input to the analyzer is a set of files, where each file is identified by
/// `FileId` and contains source code. However, another source of source code in
/// Rust are macros: each macro can be thought of as producing a "temporary