Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat(test): Inserting in method arg
  • Loading branch information
jubnzv committed Oct 3, 2023
commit ee3f98bbea64b567a38199ed9cab95822e4a8b45
19 changes: 13 additions & 6 deletions linting/ui/fail/storage_never_freed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,35 @@ pub mod storage_never_freed {
pub struct StorageNeverFreed {
// All the fields generate warnings, since there are `insert` operations for
// them, but there are no `remove` operations.
vec_field: Vec<AccountId>,
vec_field_1: Vec<AccountId>,
vec_field_subscription: Vec<AccountId>,
map_field: Mapping<AccountId, AccountId>,
map_field_1: Mapping<AccountId, AccountId>,
map_field_2: Mapping<AccountId, AccountId>,
map_field_alias: MapAlias2<AccountId, AccountId>,
}

impl StorageNeverFreed {
#[ink(constructor)]
pub fn new() -> Self {
Self {
vec_field: Vec::new(),
vec_field_1: Vec::new(),
vec_field_subscription: Vec::new(),
map_field: Mapping::new(),
map_field_1: Mapping::new(),
map_field_2: Mapping::new(),
map_field_alias: Mapping::new(),
}
}

fn flip(a: bool) -> bool {
!a
}

#[ink(message)]
pub fn add_to_fields(&mut self, v: AccountId) {
self.vec_field.push(v);
self.map_field.insert(v, &v);
self.vec_field_1.push(v);
self.vec_field_subscription[0] = v;
self.map_field_1.insert(v, &v);
let _ = Self::flip(self.map_field_2.insert(v, &v).is_some());
self.map_field_alias.insert(v, &v);
}
}
Expand Down
29 changes: 20 additions & 9 deletions linting/ui/fail/storage_never_freed.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: storage never freed
--> $DIR/storage_never_freed.rs:16:9
|
LL | map_field: Mapping<AccountId, AccountId>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | map_field_1: Mapping<AccountId, AccountId>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: the lint level is defined here
--> $DIR/storage_never_freed.rs:1:46
Expand All @@ -11,19 +11,30 @@ LL | #![cfg_attr(dylint_lib = "ink_linting", deny(storage_never_freed))]
| ^^^^^^^^^^^^^^^^^^^
help: consider adding operations to remove elements available to the user
|
LL | map_field: Mapping<AccountId, AccountId>,
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
LL | map_field_1: Mapping<AccountId, AccountId>,
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

error: storage never freed
--> $DIR/storage_never_freed.rs:17:9
|
LL | map_field_2: Mapping<AccountId, AccountId>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: consider adding operations to remove elements available to the user
|
LL | map_field_2: Mapping<AccountId, AccountId>,
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

error: storage never freed
--> $DIR/storage_never_freed.rs:14:9
|
LL | vec_field: Vec<AccountId>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^
LL | vec_field_1: Vec<AccountId>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: consider adding operations to remove elements available to the user
|
LL | vec_field: Vec<AccountId>,
| ~~~~~~~~~~~~~~~~~~~~~~~~~
LL | vec_field_1: Vec<AccountId>,
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~

error: storage never freed
--> $DIR/storage_never_freed.rs:15:9
Expand All @@ -36,5 +47,5 @@ help: consider adding operations to remove elements available to the user
LL | vec_field_subscription: Vec<AccountId>,
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

error: aborting due to 3 previous errors
error: aborting due to 4 previous errors