File tree 2 files changed +13
-19
lines changed
lints/duplicate-mutable-accounts/src
2 files changed +13
-19
lines changed Original file line number Diff line number Diff line change @@ -90,27 +90,21 @@ impl Streams {
90
90
. any ( |token_stream| Self :: is_substream ( token_stream, other) )
91
91
}
92
92
93
- /// Returns true if `other` is a substream of `stream`. By substream we mean in the
94
- /// sense of a substring.
93
+ /// Returns true if `other` is a substream of `stream`. By substream we mean in the sense of a substring.
95
94
// NOTE: a possible optimization is when a match is found, to remove the matched
96
95
// TokenTrees from the TokenStream, since the constraint has been "checked" so it never
97
96
// needs to be validated again. This cuts down the number of comparisons.
98
97
fn is_substream ( stream : & TokenStream , other : & TokenStream ) -> bool {
99
- let other_len = other. len ( ) ;
100
98
for i in 0 ..stream. len ( ) {
101
- for ( j, other_token) in other. trees ( ) . enumerate ( ) {
102
- match stream. trees ( ) . nth ( i + j) {
103
- Some ( token_tree) => {
104
- if !token_tree. eq_unspanned ( other_token) {
105
- break ;
106
- }
107
- // reached last index, so we have a match
108
- if j == other_len - 1 {
109
- return true ;
110
- }
111
- }
112
- None => return false , // reached end of stream
113
- }
99
+ if other
100
+ . trees ( )
101
+ . enumerate ( )
102
+ . all ( |( j, other_token) | match stream. trees ( ) . nth ( i + j) {
103
+ Some ( token_tree) => token_tree. eq_unspanned ( other_token) ,
104
+ None => false ,
105
+ } )
106
+ {
107
+ return true ;
114
108
}
115
109
}
116
110
false
Original file line number Diff line number Diff line change @@ -140,11 +140,11 @@ impl<'tcx> LateLintPass<'tcx> for DuplicateMutableAccounts {
140
140
self . no_alternate_constraints = true ; // assume no alternate constraints
141
141
for current in 0 ..exprs. len ( ) - 1 {
142
142
for next in current + 1 ..exprs. len ( ) {
143
- if !values. check_key_constraint ( exprs[ current] , exprs[ next] ) {
144
- self . spans . push ( ( exprs[ current] . span , exprs[ next] . span ) ) ;
145
- } else {
143
+ if values. check_key_constraint ( exprs[ current] , exprs[ next] ) {
146
144
// if there is at least one alt constraint, set flag to false
147
145
self . no_alternate_constraints = false ;
146
+ } else {
147
+ self . spans . push ( ( exprs[ current] . span , exprs[ next] . span ) ) ;
148
148
}
149
149
}
150
150
}
You can’t perform that action at this time.
0 commit comments