Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/mbe/src/lib.rs')
-rw-r--r--crates/mbe/src/lib.rs9
1 files changed, 8 insertions, 1 deletions
diff --git a/crates/mbe/src/lib.rs b/crates/mbe/src/lib.rs
index 5445f8790f..d5de56312a 100644
--- a/crates/mbe/src/lib.rs
+++ b/crates/mbe/src/lib.rs
@@ -122,6 +122,9 @@ impl fmt::Display for CountError {
}
}
+/// Index of the matched macro arm on successful expansion.
+pub type MatchedArmIndex = Option<u32>;
+
/// This struct contains AST for a single `macro_rules` definition. What might
/// be very confusing is that AST has almost exactly the same shape as
/// `tt::TokenTree`, but there's a crucial difference: in macro rules, `$ident`
@@ -251,7 +254,7 @@ impl DeclarativeMacro {
new_meta_vars: bool,
call_site: Span,
def_site_edition: Edition,
- ) -> ExpandResult<tt::Subtree<Span>> {
+ ) -> ExpandResult<(tt::Subtree<Span>, MatchedArmIndex)> {
expander::expand_rules(&self.rules, tt, marker, new_meta_vars, call_site, def_site_edition)
}
}
@@ -330,6 +333,10 @@ impl<T, E> ValueResult<T, E> {
Self { value: Default::default(), err: Some(err) }
}
+ pub fn zip_val<U>(self, other: U) -> ValueResult<(T, U), E> {
+ ValueResult { value: (self.value, other), err: self.err }
+ }
+
pub fn map<U>(self, f: impl FnOnce(T) -> U) -> ValueResult<U, E> {
ValueResult { value: f(self.value), err: self.err }
}