diff options
author | Florian Diebold <[email protected]> | 2020-03-16 17:04:07 +0000 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2020-03-16 17:38:19 +0000 |
commit | d6b622cdef6af45aff46650c247940a590afde92 (patch) | |
tree | 65cc423528e35dd578e841ed0d88640c45c58b9a /crates/ra_mbe | |
parent | d655749aaeb31461f9af923bbf0b36d219cff343 (diff) |
Some cleanup
Diffstat (limited to 'crates/ra_mbe')
-rw-r--r-- | crates/ra_mbe/src/mbe_expander.rs | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/crates/ra_mbe/src/mbe_expander.rs b/crates/ra_mbe/src/mbe_expander.rs index 0a4d73dda..3c00e3b64 100644 --- a/crates/ra_mbe/src/mbe_expander.rs +++ b/crates/ra_mbe/src/mbe_expander.rs | |||
@@ -20,18 +20,20 @@ fn expand_rules(rules: &[crate::Rule], input: &tt::Subtree) -> ExpandResult<tt:: | |||
20 | for rule in rules { | 20 | for rule in rules { |
21 | let ExpandResult(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 | // Unconditionally returning the transcription here makes the | ||
25 | // `test_repeat_bad_var` test fail. | ||
24 | let ExpandResult(res, transcribe_err) = | 26 | let ExpandResult(res, transcribe_err) = |
25 | transcriber::transcribe(&rule.rhs, &new_match.bindings); | 27 | transcriber::transcribe(&rule.rhs, &new_match.bindings); |
26 | if transcribe_err.is_none() { | 28 | if transcribe_err.is_none() { |
27 | return ExpandResult::ok(res); | 29 | return ExpandResult::ok(res); |
28 | } | 30 | } |
29 | } | 31 | } |
30 | // use the rule if we matched more tokens, or had fewer patterns left | 32 | // Use the rule if we matched more tokens, or had fewer patterns left, |
33 | // or had no error | ||
31 | if let Some((prev_match, _)) = &match_ { | 34 | if let Some((prev_match, _)) = &match_ { |
32 | if new_match.unmatched_tokens < prev_match.unmatched_tokens | 35 | if (new_match.unmatched_tokens, new_match.unmatched_patterns) |
33 | || new_match.unmatched_tokens == prev_match.unmatched_tokens | 36 | < (prev_match.unmatched_tokens, prev_match.unmatched_patterns) |
34 | && new_match.unmatched_patterns < prev_match.unmatched_patterns | ||
35 | || err.is_some() && bindings_err.is_none() | 37 | || err.is_some() && bindings_err.is_none() |
36 | { | 38 | { |
37 | match_ = Some((new_match, rule)); | 39 | match_ = Some((new_match, rule)); |