Skip to content

Commit 4b63fbe

Browse files
committed
fix clippy errors
1 parent 1bcac3d commit 4b63fbe

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

lints/duplicate-mutable-accounts/src/anchor_constraint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ fn create_token_from_ident(s: &str) -> TokenTree {
8383
pub struct Streams(pub Vec<TokenStream>);
8484

8585
impl Streams {
86-
/// Returns true if `self` has a TokenStream that `other` is a substream of
86+
/// Returns true if `self` has a `TokenStream` that `other` is a substream of
8787
pub fn contains(&self, other: &TokenStream) -> bool {
8888
self.0
8989
.iter()

lints/duplicate-mutable-accounts/src/lib.rs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ extern crate rustc_span;
99
mod alternate_constraint;
1010
mod anchor_constraint;
1111

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+
};
1416

1517
use std::collections::{HashMap, VecDeque};
1618
use std::default::Default;
@@ -148,10 +150,23 @@ impl<'tcx> LateLintPass<'tcx> for DuplicateMutableAccounts {
148150

149151
fn check_crate_post(&mut self, cx: &LateContext<'tcx>) {
150152
// 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 {
152167
for v in self.accounts.values() {
153168
if v.len() > 1 {
154-
let mut deq = VecDeque::from(v.to_owned());
169+
let mut deq = VecDeque::from(v.clone());
155170
for _ in 0..deq.len() - 1 {
156171
let (first, first_span) = deq.pop_front().unwrap();
157172
for (other, other_span) in &deq {
@@ -175,19 +190,6 @@ impl<'tcx> LateLintPass<'tcx> for DuplicateMutableAccounts {
175190
}
176191
}
177192
}
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-
}
191193
}
192194
}
193195
}

0 commit comments

Comments
 (0)