@@ -93,17 +93,17 @@ impl<'tcx> LateLintPass<'tcx> for DuplicateMutableAccounts {
93
93
94
94
fn check_crate_post ( & mut self , cx : & LateContext < ' tcx > ) {
95
95
// println!("{:#?}", self);
96
- for ( _ , v ) in self . accounts . iter ( ) {
96
+ for v in self . accounts . values ( ) {
97
97
if v. len ( ) > 1 {
98
98
let gen_constraints = generate_possible_expected_constraints ( v) ;
99
99
100
100
for ( ( one, symmetric) , symbols) in gen_constraints {
101
- if !( self . streams . contains ( one) || self . streams . contains ( symmetric) ) {
101
+ if !( self . streams . contains ( & one) || self . streams . contains ( & symmetric) ) {
102
102
// get spans for offending types
103
103
let mut spans: Vec < Span > = Vec :: new ( ) ;
104
104
for ( sym, span) in v {
105
105
if & symbols. 0 == sym || & symbols. 1 == sym {
106
- spans. push ( span. clone ( ) ) ;
106
+ spans. push ( * span) ;
107
107
}
108
108
}
109
109
@@ -129,7 +129,7 @@ fn get_anchor_account_type_def_id(field: &FieldDef) -> Option<DefId> {
129
129
if_chain ! {
130
130
if let TyKind :: Path ( qpath) = & field. ty. kind;
131
131
if let QPath :: Resolved ( _, path) = qpath;
132
- if path. segments. len ( ) > 0 ;
132
+ if ! path. segments. is_empty ( ) ;
133
133
if let Some ( generic_args) = path. segments[ 0 ] . args;
134
134
if generic_args. args. len( ) == ANCHOR_ACCOUNT_GENERIC_ARG_COUNT ;
135
135
if let GenericArg :: Type ( hir_ty) = & generic_args. args[ 1 ] ;
@@ -166,7 +166,7 @@ fn split(stream: CursorRef, delimiter: TokenKind) -> Vec<TokenStream> {
166
166
split_streams. push ( TokenStream :: new ( temp. clone ( ) ) ) ;
167
167
temp. clear ( ) ;
168
168
} else {
169
- temp. push ( TreeAndSpacing :: from ( t. to_owned ( ) ) ) ;
169
+ temp. push ( TreeAndSpacing :: from ( t. clone ( ) ) ) ;
170
170
}
171
171
} ) ;
172
172
split_streams. push ( TokenStream :: new ( temp) ) ;
@@ -181,25 +181,25 @@ fn split(stream: CursorRef, delimiter: TokenKind) -> Vec<TokenStream> {
181
181
/// symmetric value, e.g., `a!=b` and `b!=a`. The second field of the tuple is a tuple of symbols, which
182
182
/// represent the identifiers being compared. Following the previous example, this would be `(a, b)`.
183
183
fn generate_possible_expected_constraints (
184
- identical_types : & Vec < ( Symbol , Span ) > ,
184
+ identical_types : & [ ( Symbol , Span ) ] ,
185
185
) -> Vec < ( ( TokenStream , TokenStream ) , ( Symbol , Symbol ) ) > {
186
- let mut deq = VecDeque :: from ( identical_types. clone ( ) ) ;
186
+ let mut deq = VecDeque :: from ( identical_types. to_owned ( ) ) ;
187
187
let mut gen_set = Vec :: new ( ) ;
188
188
189
189
for _ in 0 ..deq. len ( ) - 1 {
190
190
let first = deq. pop_front ( ) . unwrap ( ) . 0 ;
191
191
// generate stream for all other values in vec
192
192
for ( other, _) in & deq {
193
- let stream = create_key_check_constraint_tokenstream ( & first, other) ;
194
- let symmetric_stream = create_key_check_constraint_tokenstream ( other, & first) ;
195
- gen_set. push ( ( ( stream, symmetric_stream) , ( first, other. clone ( ) ) ) ) ;
193
+ let stream = create_key_check_constraint_tokenstream ( first, * other) ;
194
+ let symmetric_stream = create_key_check_constraint_tokenstream ( * other, first) ;
195
+ gen_set. push ( ( ( stream, symmetric_stream) , ( first, * other) ) ) ;
196
196
}
197
197
}
198
198
gen_set
199
199
}
200
200
201
201
/// Returns a `TokenStream` of form: constraint = `a`.key() != `b`.key().
202
- fn create_key_check_constraint_tokenstream ( a : & Symbol , b : & Symbol ) -> TokenStream {
202
+ fn create_key_check_constraint_tokenstream ( a : Symbol , b : Symbol ) -> TokenStream {
203
203
// TODO: may be more efficient way to do this, since the stream is effectively fixed
204
204
// and determined. Only two tokens are variable.
205
205
let constraint = vec ! [
@@ -239,8 +239,8 @@ pub struct Streams(Vec<TokenStream>);
239
239
impl Streams {
240
240
/// Returns true if `self` contains `other`, by comparing if there is an
241
241
/// identical `TokenStream` in `self` regardless of span.
242
- fn contains ( & self , other : TokenStream ) -> bool {
243
- self . 0 . iter ( ) . any ( |stream| stream. eq_unspanned ( & other) )
242
+ fn contains ( & self , other : & TokenStream ) -> bool {
243
+ self . 0 . iter ( ) . any ( |stream| stream. eq_unspanned ( other) )
244
244
}
245
245
}
246
246
@@ -258,3 +258,13 @@ fn insecure_2() {
258
258
fn secure ( ) {
259
259
dylint_testing:: ui_test_example ( env ! ( "CARGO_PKG_NAME" ) , "secure" ) ;
260
260
}
261
+
262
+ #[ test]
263
+ fn recommended ( ) {
264
+ dylint_testing:: ui_test_example ( env ! ( "CARGO_PKG_NAME" ) , "recommended" ) ;
265
+ }
266
+
267
+ #[ test]
268
+ fn recommended_2 ( ) {
269
+ dylint_testing:: ui_test_example ( env ! ( "CARGO_PKG_NAME" ) , "recommended-2" ) ;
270
+ }
0 commit comments