From 2c85db8eb6bac4a9106e7373840c0b3d209188a6 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Thu, 26 Nov 2020 16:56:22 +0100 Subject: Implement `Display` for macro expansion errors --- crates/mbe/src/lib.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'crates/mbe') diff --git a/crates/mbe/src/lib.rs b/crates/mbe/src/lib.rs index 22fbf9a80..844e5a117 100644 --- a/crates/mbe/src/lib.rs +++ b/crates/mbe/src/lib.rs @@ -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 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, -- cgit v1.2.3