5
5
mod matcher;
6
6
mod transcriber;
7
7
8
- use rustc_hash :: FxHashMap ;
8
+ use smallvec :: SmallVec ;
9
9
use syntax:: SmolStr ;
10
10
11
11
use crate :: { ExpandError , ExpandResult } ;
@@ -28,10 +28,10 @@ pub(crate) fn expand_rules(
28
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
32
if let Some ( ( prev_match, _) ) = & match_ {
33
- if ( new_match. unmatched_tts , new_match. err_count )
34
- < ( prev_match. unmatched_tts , prev_match. err_count )
33
+ if ( new_match. unmatched_tts , - ( new_match. bound_count as i32 ) )
34
+ < ( prev_match. unmatched_tts , - ( prev_match. bound_count as i32 ) )
35
35
{
36
36
match_ = Some ( ( new_match, rule) ) ;
37
37
}
@@ -94,19 +94,19 @@ pub(crate) fn expand_rules(
94
94
/// In other words, `Bindings` is a *multi* mapping from `SmolStr` to
95
95
/// `tt::TokenTree`, where the index to select a particular `TokenTree` among
96
96
/// many is not a plain `usize`, but an `&[usize]`.
97
- #[ derive( Debug , Default ) ]
97
+ #[ derive( Debug , Default , Clone , PartialEq , Eq ) ]
98
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
103
enum Binding {
104
104
Fragment ( Fragment ) ,
105
105
Nested ( Vec < Binding > ) ,
106
106
Empty ,
107
107
}
108
108
109
- #[ derive( Debug , Clone ) ]
109
+ #[ derive( Debug , Clone , PartialEq , Eq ) ]
110
110
enum Fragment {
111
111
/// token fragments are just copy-pasted into the output
112
112
Tokens ( tt:: TokenTree ) ,
0 commit comments