@@ -9,8 +9,10 @@ extern crate rustc_span;
9
9
mod alternate_constraint;
10
10
mod anchor_constraint;
11
11
12
- use crate :: alternate_constraint:: * ;
13
- use crate :: anchor_constraint:: * ;
12
+ use crate :: alternate_constraint:: Values ;
13
+ use crate :: anchor_constraint:: {
14
+ create_key_check_constraint_tokenstream, get_anchor_account_type_def_id, get_def_id, Streams ,
15
+ } ;
14
16
15
17
use std:: collections:: { HashMap , VecDeque } ;
16
18
use std:: default:: Default ;
@@ -148,10 +150,23 @@ impl<'tcx> LateLintPass<'tcx> for DuplicateMutableAccounts {
148
150
149
151
fn check_crate_post ( & mut self , cx : & LateContext < ' tcx > ) {
150
152
// if collected some anchor macro constraints then perform v1 lint
151
- if !self . streams . 0 . is_empty ( ) {
153
+ if self . streams . 0 . is_empty ( ) {
154
+ // TODO: Not a fan of having it span lints for this check when there are no checks whatsoever.
155
+ // I'd rather have it span lints to recommended anchor macros, if no checks are found at all
156
+ for ( first, second) in & self . spans {
157
+ span_lint_and_help (
158
+ cx,
159
+ DUPLICATE_MUTABLE_ACCOUNTS ,
160
+ * first,
161
+ & format ! ( "the expressions on line {:?} and {:?} have identical Account types, yet do not contain a proper key check." , first, second) ,
162
+ Some ( * second) ,
163
+ "add a key check to make sure the accounts have different keys, e.g., x.key() != y.key()" ,
164
+ ) ;
165
+ }
166
+ } else {
152
167
for v in self . accounts . values ( ) {
153
168
if v. len ( ) > 1 {
154
- let mut deq = VecDeque :: from ( v. to_owned ( ) ) ;
169
+ let mut deq = VecDeque :: from ( v. clone ( ) ) ;
155
170
for _ in 0 ..deq. len ( ) - 1 {
156
171
let ( first, first_span) = deq. pop_front ( ) . unwrap ( ) ;
157
172
for ( other, other_span) in & deq {
@@ -175,19 +190,6 @@ impl<'tcx> LateLintPass<'tcx> for DuplicateMutableAccounts {
175
190
}
176
191
}
177
192
}
178
- } else {
179
- // TODO: Not a fan of having it span lints for this check when there are no checks whatsoever.
180
- // I'd rather have it span lints to recommended anchor macros, if no checks are found at all
181
- for ( first, second) in & self . spans {
182
- span_lint_and_help (
183
- cx,
184
- DUPLICATE_MUTABLE_ACCOUNTS ,
185
- * first,
186
- & format ! ( "the expressions on line {:?} and {:?} have identical Account types, yet do not contain a proper key check." , first, second) ,
187
- Some ( * second) ,
188
- "add a key check to make sure the accounts have different keys, e.g., x.key() != y.key()" ,
189
- ) ;
190
- }
191
193
}
192
194
}
193
195
}
0 commit comments