mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-14 17:07:26 +00:00
Merge #6640
6640: Implement `Display` for macro expansion errors r=jonas-schievink a=jonas-schievink Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
This commit is contained in:
commit
ad343870ec
2 changed files with 27 additions and 0 deletions
|
@ -12,6 +12,8 @@ mod subtree_source;
|
|||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
use std::fmt;
|
||||
|
||||
pub use tt::{Delimiter, Punct};
|
||||
|
||||
use crate::{
|
||||
|
@ -42,6 +44,20 @@ impl From<tt::ExpansionError> for ExpandError {
|
|||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for ExpandError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
ExpandError::NoMatchingRule => f.write_str("no rule matches input tokens"),
|
||||
ExpandError::UnexpectedToken => f.write_str("unexpected token in input"),
|
||||
ExpandError::BindingError(e) => f.write_str(e),
|
||||
ExpandError::ConversionError => f.write_str("could not convert tokens"),
|
||||
ExpandError::InvalidRepeat => f.write_str("invalid repeat expression"),
|
||||
ExpandError::ProcMacroError(e) => write!(f, "{}", e),
|
||||
ExpandError::Other(e) => f.write_str(e),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub use crate::syntax_bridge::{
|
||||
ast_to_token_tree, parse_to_token_tree, syntax_node_to_token_tree, token_tree_to_syntax_node,
|
||||
TokenMap,
|
||||
|
|
|
@ -240,6 +240,17 @@ pub enum ExpansionError {
|
|||
ExpansionError(String),
|
||||
}
|
||||
|
||||
impl fmt::Display for ExpansionError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
ExpansionError::IOError(e) => write!(f, "I/O error: {}", e),
|
||||
ExpansionError::JsonError(e) => write!(f, "JSON decoding error: {}", e),
|
||||
ExpansionError::Unknown(e) => write!(f, "{}", e),
|
||||
ExpansionError::ExpansionError(e) => write!(f, "proc macro returned error: {}", e),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait TokenExpander: Debug + Send + Sync + RefUnwindSafe {
|
||||
fn expand(&self, subtree: &Subtree, attrs: Option<&Subtree>)
|
||||
-> Result<Subtree, ExpansionError>;
|
||||
|
|
Loading…
Reference in a new issue