Skip to content

Commit 159401c

Browse files
committed
fix lint spanning deduplication issue
1 parent fbd387e commit 159401c

File tree

4 files changed

+30
-32
lines changed

4 files changed

+30
-32
lines changed

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

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,6 @@ impl<'tcx> LateLintPass<'tcx> for DuplicateMutableAccounts {
8383
if name.as_str() == "account";
8484
if let MacArgs::Delimited(_, _, token_stream) = &attr_item.args;
8585
then {
86-
// Parse each constraint as a separate TokenStream
87-
// for delimited_stream in split(token_stream.trees(), TokenKind::Comma) {
88-
// self.streams.0.push(delimited_stream);
89-
// }
9086
self.streams.0.push(token_stream.clone());
9187
}
9288
}
@@ -107,13 +103,11 @@ impl<'tcx> LateLintPass<'tcx> for DuplicateMutableAccounts {
107103
if !(self.streams.contains(&stream)
108104
|| self.streams.contains(&symmetric_stream))
109105
{
110-
// NOTE: for some reason, will only print out 2 messages, not 3
111-
// println!("spanning lint");
112106
span_lint_and_help(
113107
cx,
114108
DUPLICATE_MUTABLE_ACCOUNTS,
115109
first_span,
116-
"identical account types without a key check constraint",
110+
&format!("{} and {} have identical account types but do not have a key check constraint", first, other),
117111
Some(*other_span),
118112
&format!("add an anchor key check constraint: #[account(constraint = {}.key() != {}.key())]", first, other)
119113
);
@@ -212,7 +206,6 @@ impl Streams {
212206
for (j, other_token) in other.trees().enumerate() {
213207
match stream.trees().nth(i + j) {
214208
Some(token_tree) => {
215-
// println!("Comparing {:#?} with {:#?}", token_tree, other_tokens[j]);
216209
if !token_tree.eq_unspanned(other_token) {
217210
break;
218211
}
@@ -229,24 +222,6 @@ impl Streams {
229222
}
230223
}
231224

232-
// /// Splits `stream` into a vector of substreams, separated by `delimiter`.
233-
// fn split(stream: CursorRef, delimiter: TokenKind) -> Vec<TokenStream> {
234-
// let mut split_streams: Vec<TokenStream> = Vec::new();
235-
// let mut temp: Vec<TreeAndSpacing> = Vec::new();
236-
// let delim = TokenTree::Token(Token::new(delimiter, DUMMY_SP));
237-
238-
// stream.for_each(|t| {
239-
// if t.eq_unspanned(&delim) {
240-
// split_streams.push(TokenStream::new(temp.clone()));
241-
// temp.clear();
242-
// } else {
243-
// temp.push(TreeAndSpacing::from(t.clone()));
244-
// }
245-
// });
246-
// split_streams.push(TokenStream::new(temp));
247-
// split_streams
248-
// }
249-
250225
#[test]
251226
fn insecure() {
252227
dylint_testing::ui_test_example(env!("CARGO_PKG_NAME"), "insecure");

lints/duplicate-mutable-accounts/ui/insecure-2/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ pub mod duplicate_mutable_accounts_insecure {
2222

2323
#[derive(Accounts)]
2424
pub struct Update<'info> {
25-
#[account(constraint = user_a.key() != user_b.key(), constraint = user_b.key() != user_c.key())]
2625
user_a: Account<'info, User>,
2726
user_b: Account<'info, User>,
2827
user_c: Account<'info, User>,
Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,39 @@
1-
error: identical account types without a key check constraint
2-
--> $DIR/lib.rs:26:5
1+
error: user_a and user_b have identical account types but do not have a key check constraint
2+
--> $DIR/lib.rs:25:5
33
|
44
LL | user_a: Account<'info, User>,
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: `-D duplicate-mutable-accounts` implied by `-D warnings`
8+
help: add an anchor key check constraint: #[account(constraint = user_a.key() != user_b.key())]
9+
--> $DIR/lib.rs:26:5
10+
|
11+
LL | user_b: Account<'info, User>,
12+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13+
14+
error: user_a and user_c have identical account types but do not have a key check constraint
15+
--> $DIR/lib.rs:25:5
16+
|
17+
LL | user_a: Account<'info, User>,
18+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19+
|
820
help: add an anchor key check constraint: #[account(constraint = user_a.key() != user_c.key())]
9-
--> $DIR/lib.rs:28:5
21+
--> $DIR/lib.rs:27:5
22+
|
23+
LL | user_c: Account<'info, User>,
24+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25+
26+
error: user_b and user_c have identical account types but do not have a key check constraint
27+
--> $DIR/lib.rs:26:5
28+
|
29+
LL | user_b: Account<'info, User>,
30+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
31+
|
32+
help: add an anchor key check constraint: #[account(constraint = user_b.key() != user_c.key())]
33+
--> $DIR/lib.rs:27:5
1034
|
1135
LL | user_c: Account<'info, User>,
1236
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1337

14-
error: aborting due to previous error
38+
error: aborting due to 3 previous errors
1539

lints/duplicate-mutable-accounts/ui/insecure/src/lib.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: identical account types without a key check constraint
1+
error: user_a and user_b have identical account types but do not have a key check constraint
22
--> $DIR/lib.rs:25:5
33
|
44
LL | user_a: Account<'info, User>,

0 commit comments

Comments
 (0)