]> git.lizzy.rs Git - rust.git/commitdiff
Some cleanup
authorFlorian Diebold <flodiebold@gmail.com>
Mon, 16 Mar 2020 17:04:07 +0000 (18:04 +0100)
committerFlorian Diebold <flodiebold@gmail.com>
Mon, 16 Mar 2020 17:38:19 +0000 (18:38 +0100)
crates/ra_mbe/src/mbe_expander.rs

index 0a4d73dda24f7a4ca6442fde16ef94da693477c8..3c00e3b64d4d1ad80d963e909fc4d37ed4d7c31f 100644 (file)
@@ -20,18 +20,20 @@ fn expand_rules(rules: &[crate::Rule], input: &tt::Subtree) -> ExpandResult<tt::
     for rule in rules {
         let ExpandResult(new_match, bindings_err) = matcher::match_(&rule.lhs, input);
         if bindings_err.is_none() {
-            // if we find a rule that applies without errors, we're done
+            // If we find a rule that applies without errors, we're done.
+            // Unconditionally returning the transcription here makes the
+            // `test_repeat_bad_var` test fail.
             let ExpandResult(res, transcribe_err) =
                 transcriber::transcribe(&rule.rhs, &new_match.bindings);
             if transcribe_err.is_none() {
                 return ExpandResult::ok(res);
             }
         }
-        // use the rule if we matched more tokens, or had fewer patterns left
+        // Use the rule if we matched more tokens, or had fewer patterns left,
+        // or had no error
         if let Some((prev_match, _)) = &match_ {
-            if new_match.unmatched_tokens < prev_match.unmatched_tokens
-                || new_match.unmatched_tokens == prev_match.unmatched_tokens
-                    && new_match.unmatched_patterns < prev_match.unmatched_patterns
+            if (new_match.unmatched_tokens, new_match.unmatched_patterns)
+                < (prev_match.unmatched_tokens, prev_match.unmatched_patterns)
                 || err.is_some() && bindings_err.is_none()
             {
                 match_ = Some((new_match, rule));