Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unused_self false positive #5351

Closed
snejugal opened this issue Mar 22, 2020 · 1 comment · Fixed by #5387
Closed

unused_self false positive #5351

snejugal opened this issue Mar 22, 2020 · 1 comment · Fixed by #5387
Labels
C-bug Category: Clippy is not doing the correct thing

Comments

@snejugal
Copy link

pub struct Foo;

impl Foo {
    #[deny(clippy::unused_self)]
    pub fn foo((): ()) {} # can be any tuple, but it is important to destructure it

    pub fn consume(self) {}
}

(I denied the lint on the specific item so that I don't have to allow it on the second one, removing which no longer causes the bug)

Running clippy outputs this:


$ cargo clippy
    Checking clippy-bug v0.1.0 (/home/snejugal/stuff/clippy-bug)
error: unused `self` argument
 --> src/lib.rs:5:16
  |
5 |     pub fn foo((): ()) {}
  |                ^^^^^^^
  |
note: lint level defined here
 --> src/lib.rs:4:12
  |
4 |     #[deny(clippy::unused_self)]
  |            ^^^^^^^^^^^^^^^^^^^
  = help: consider refactoring to a associated function
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unused_self
...

I can reproduce on 1.42 (clippy 0.0.212 (4ee1206 2020-02-01)) and latest nightly (clippy 0.0.212 (23549a8 2020-03-16)). However, it works correctly on 1.41 (clippy 0.0.212 (69f99e7 2019-12-14)).

@flip1995 flip1995 added A-musing C-bug Category: Clippy is not doing the correct thing labels Mar 23, 2020
@jpospychala
Copy link
Contributor

unused_self lint was initially meant for impl blocks, recently it was modified to allow on function level and here is where things went wrong. For an impl item for which it is enabled, it takes parent Impl and iterates over all of it's functions, thus enabling lint for one function enables it for all functions in Impl block.

bors added a commit that referenced this issue Mar 30, 2020
`unused_self` false positive

fixes #5351

Remove the for loop in `unused_self` so that lint enabled for one method doesn't trigger on another method.
bors added a commit that referenced this issue Mar 30, 2020
`unused_self` false positive

fixes #5351

Remove the for loop in `unused_self` so that lint enabled for one method doesn't trigger on another method.
@bors bors closed this as completed in 563da52 Mar 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants