diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-11-26 15:56:58 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-11-26 15:56:58 +0000 |
commit | ad343870ec33d744f0efbd1d9633e62b017b19ea (patch) | |
tree | 6424b095680383a82ad8d4d9f4b239bcdbc9cdcd /crates/mbe/src | |
parent | db061fb274ddc9a8820c5f0c90b077c88961d1be (diff) | |
parent | 2c85db8eb6bac4a9106e7373840c0b3d209188a6 (diff) |
Merge #6640
6640: Implement `Display` for macro expansion errors r=jonas-schievink a=jonas-schievink
Co-authored-by: Jonas Schievink <[email protected]>
Diffstat (limited to 'crates/mbe/src')
-rw-r--r-- | crates/mbe/src/lib.rs | 16 |
1 files changed, 16 insertions, 0 deletions
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; | |||
12 | #[cfg(test)] | 12 | #[cfg(test)] |
13 | mod tests; | 13 | mod tests; |
14 | 14 | ||
15 | use std::fmt; | ||
16 | |||
15 | pub use tt::{Delimiter, Punct}; | 17 | pub use tt::{Delimiter, Punct}; |
16 | 18 | ||
17 | use crate::{ | 19 | use crate::{ |
@@ -42,6 +44,20 @@ impl From<tt::ExpansionError> for ExpandError { | |||
42 | } | 44 | } |
43 | } | 45 | } |
44 | 46 | ||
47 | impl fmt::Display for ExpandError { | ||
48 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
49 | match self { | ||
50 | ExpandError::NoMatchingRule => f.write_str("no rule matches input tokens"), | ||
51 | ExpandError::UnexpectedToken => f.write_str("unexpected token in input"), | ||
52 | ExpandError::BindingError(e) => f.write_str(e), | ||
53 | ExpandError::ConversionError => f.write_str("could not convert tokens"), | ||
54 | ExpandError::InvalidRepeat => f.write_str("invalid repeat expression"), | ||
55 | ExpandError::ProcMacroError(e) => write!(f, "{}", e), | ||
56 | ExpandError::Other(e) => f.write_str(e), | ||
57 | } | ||
58 | } | ||
59 | } | ||
60 | |||
45 | pub use crate::syntax_bridge::{ | 61 | pub use crate::syntax_bridge::{ |
46 | ast_to_token_tree, parse_to_token_tree, syntax_node_to_token_tree, token_tree_to_syntax_node, | 62 | ast_to_token_tree, parse_to_token_tree, syntax_node_to_token_tree, token_tree_to_syntax_node, |
47 | TokenMap, | 63 | TokenMap, |