Rust-clippy: Lint methods which have "self" argument but don't use it.

Created on 17 Sep 2019  路  2Comments  路  Source: rust-lang/rust-clippy

If we have a code like this:

struct A;
impl A {
    fn method(&self) {
        // do something, but don't use self.
    }
}

We could highlight "unused self" and advise to refactor it to a static method or a function. The same lint has been in Python language for a decade, I believe.

Note: if the self argument is unused within a trait, we should not lint this, because this becomes a part of a generic interface, which could have been done intentionally.

A-complexity A-suggestion L-lint

Most helpful comment

Hi, I'd like to work on this issue :)

All 2 comments

Hi, I'd like to work on this issue :)

Please note, that in such methods we should also treat any form of accepting self argument there: by reference, mutable reference, pointers, moving, anything.

Was this page helpful?
0 / 5 - 0 ratings