diff options
Diffstat (limited to 'crates/mbe/src/expander.rs')
-rw-r--r-- | crates/mbe/src/expander.rs | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/crates/mbe/src/expander.rs b/crates/mbe/src/expander.rs index e7e14b3cc..2efff8f52 100644 --- a/crates/mbe/src/expander.rs +++ b/crates/mbe/src/expander.rs | |||
@@ -5,7 +5,7 @@ | |||
5 | mod matcher; | 5 | mod matcher; |
6 | mod transcriber; | 6 | mod transcriber; |
7 | 7 | ||
8 | use rustc_hash::FxHashMap; | 8 | use smallvec::SmallVec; |
9 | use syntax::SmolStr; | 9 | use syntax::SmolStr; |
10 | 10 | ||
11 | use crate::{ExpandError, ExpandResult}; | 11 | use crate::{ExpandError, ExpandResult}; |
@@ -28,10 +28,10 @@ pub(crate) fn expand_rules( | |||
28 | return ExpandResult::ok(value); | 28 | return ExpandResult::ok(value); |
29 | } | 29 | } |
30 | } | 30 | } |
31 | // Use the rule if we matched more tokens, or had fewer errors | 31 | // Use the rule if we matched more tokens, or bound variables count |
32 | if let Some((prev_match, _)) = &match_ { | 32 | if let Some((prev_match, _)) = &match_ { |
33 | if (new_match.unmatched_tts, new_match.err_count) | 33 | if (new_match.unmatched_tts, -(new_match.bound_count as i32)) |
34 | < (prev_match.unmatched_tts, prev_match.err_count) | 34 | < (prev_match.unmatched_tts, -(prev_match.bound_count as i32)) |
35 | { | 35 | { |
36 | match_ = Some((new_match, rule)); | 36 | match_ = Some((new_match, rule)); |
37 | } | 37 | } |
@@ -94,19 +94,19 @@ pub(crate) fn expand_rules( | |||
94 | /// In other words, `Bindings` is a *multi* mapping from `SmolStr` to | 94 | /// In other words, `Bindings` is a *multi* mapping from `SmolStr` to |
95 | /// `tt::TokenTree`, where the index to select a particular `TokenTree` among | 95 | /// `tt::TokenTree`, where the index to select a particular `TokenTree` among |
96 | /// many is not a plain `usize`, but an `&[usize]`. | 96 | /// many is not a plain `usize`, but an `&[usize]`. |
97 | #[derive(Debug, Default)] | 97 | #[derive(Debug, Default, Clone, PartialEq, Eq)] |
98 | struct Bindings { | 98 | struct Bindings { |
99 | inner: FxHashMap<SmolStr, Binding>, | 99 | inner: SmallVec<[(SmolStr, Binding); 4]>, |
100 | } | 100 | } |
101 | 101 | ||
102 | #[derive(Debug)] | 102 | #[derive(Debug, Clone, PartialEq, Eq)] |
103 | enum Binding { | 103 | enum Binding { |
104 | Fragment(Fragment), | 104 | Fragment(Fragment), |
105 | Nested(Vec<Binding>), | 105 | Nested(Vec<Binding>), |
106 | Empty, | 106 | Empty, |
107 | } | 107 | } |
108 | 108 | ||
109 | #[derive(Debug, Clone)] | 109 | #[derive(Debug, Clone, PartialEq, Eq)] |
110 | enum Fragment { | 110 | enum Fragment { |
111 | /// token fragments are just copy-pasted into the output | 111 | /// token fragments are just copy-pasted into the output |
112 | Tokens(tt::TokenTree), | 112 | Tokens(tt::TokenTree), |