gear-tech / sails

Framework for ultimate experience of writing programs powered by Gear protocol
Apache License 2.0
17 stars 4 forks source link

Seems like `sails_rs::program/service` ignore attributes on methods #526

Closed gshep closed 1 week ago

gshep commented 3 weeks ago

Problem

While working on gas estimation for reply hook I faced the issue with attributes on service/program methods. Looks like the attributes are completely ignored.

Steps

  1. cargo-sails new-program test-attriute

[derive(Clone, Debug, Decode, TypeInfo)]

[codec(crate = sails_rs::scale_codec)]

[scale_info(crate = sails_rs::scale_info)]

struct Input { n: u32, }

[sails_rs::service]

impl TestAttributeService { pub fn new() -> Self { Self(()) }

// Service's method (command)
#[allow(unused_mut)]
pub fn do_something(&mut self, mut input: Input) -> String {
    input.n += 1;
    "Hello from TestAttribute!".to_string()
}

}

3. `cargo b`
4. build log is attached. There is the warning that `mut` is not necessary however it is and the redundant attribute has been applied.

### Possible Solution

_No response_

### Notes

_No response_

### Relevant Log Output

<details><summary>Click to expand/collapse</summary>
<p>
warning: variable does not need to be mutable --> app/src/lib.rs:29:36 29 pub fn do_something(&mut self, mut input: Input) -> String { ----^^^^^
help: remove this mut

= note: #[warn(unused_mut)] on by default



</p>
</details>