diff options
Diffstat (limited to 'crates/ra_mbe/src/mbe_expander.rs')
-rw-r--r-- | crates/ra_mbe/src/mbe_expander.rs | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/crates/ra_mbe/src/mbe_expander.rs b/crates/ra_mbe/src/mbe_expander.rs index 204c30e3d..0a4d73dda 100644 --- a/crates/ra_mbe/src/mbe_expander.rs +++ b/crates/ra_mbe/src/mbe_expander.rs | |||
@@ -18,12 +18,13 @@ fn expand_rules(rules: &[crate::Rule], input: &tt::Subtree) -> ExpandResult<tt:: | |||
18 | let mut match_: Option<(matcher::Match, &crate::Rule)> = None; | 18 | let mut match_: Option<(matcher::Match, &crate::Rule)> = None; |
19 | let mut err = Some(ExpandError::NoMatchingRule); | 19 | let mut err = Some(ExpandError::NoMatchingRule); |
20 | for rule in rules { | 20 | for rule in rules { |
21 | let (new_match, bindings_err) = matcher::match_(&rule.lhs, input); | 21 | let ExpandResult(new_match, bindings_err) = matcher::match_(&rule.lhs, input); |
22 | if bindings_err.is_none() { | 22 | if bindings_err.is_none() { |
23 | // if we find a rule that applies without errors, we're done | 23 | // if we find a rule that applies without errors, we're done |
24 | let (res, transcribe_err) = transcriber::transcribe(&rule.rhs, &new_match.bindings); | 24 | let ExpandResult(res, transcribe_err) = |
25 | transcriber::transcribe(&rule.rhs, &new_match.bindings); | ||
25 | if transcribe_err.is_none() { | 26 | if transcribe_err.is_none() { |
26 | return (res, None); | 27 | return ExpandResult::ok(res); |
27 | } | 28 | } |
28 | } | 29 | } |
29 | // use the rule if we matched more tokens, or had fewer patterns left | 30 | // use the rule if we matched more tokens, or had fewer patterns left |
@@ -43,10 +44,11 @@ fn expand_rules(rules: &[crate::Rule], input: &tt::Subtree) -> ExpandResult<tt:: | |||
43 | } | 44 | } |
44 | if let Some((match_, rule)) = match_ { | 45 | if let Some((match_, rule)) = match_ { |
45 | // if we got here, there was no match without errors | 46 | // if we got here, there was no match without errors |
46 | let (result, transcribe_err) = transcriber::transcribe(&rule.rhs, &match_.bindings); | 47 | let ExpandResult(result, transcribe_err) = |
47 | (result, err.or(transcribe_err)) | 48 | transcriber::transcribe(&rule.rhs, &match_.bindings); |
49 | ExpandResult(result, err.or(transcribe_err)) | ||
48 | } else { | 50 | } else { |
49 | (tt::Subtree::default(), err) | 51 | ExpandResult(tt::Subtree::default(), err) |
50 | } | 52 | } |
51 | } | 53 | } |
52 | 54 | ||
@@ -171,6 +173,6 @@ mod tests { | |||
171 | ast_to_token_tree(¯o_invocation.token_tree().unwrap()).unwrap(); | 173 | ast_to_token_tree(¯o_invocation.token_tree().unwrap()).unwrap(); |
172 | 174 | ||
173 | let expanded = expand_rules(&rules.rules, &invocation_tt); | 175 | let expanded = expand_rules(&rules.rules, &invocation_tt); |
174 | (expanded.0, expanded.1) | 176 | expanded |
175 | } | 177 | } |
176 | } | 178 | } |