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

use_self false negative on tuple or struct enum variants #8845

Closed
awused opened this issue May 19, 2022 · 2 comments · Fixed by #8899
Closed

use_self false negative on tuple or struct enum variants #8845

awused opened this issue May 19, 2022 · 2 comments · Fixed by #8899
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't

Comments

@awused
Copy link

awused commented May 19, 2022

Summary

use_self doesn't trigger for struct or tuple enum variants, only empty variants.

There are false negatives mentioned in the documention for use_self but I couldn't find an issue tracking them. I don't know if these are the same known false negatives or not.

Lint Name

use_self

Reproducer

I tried this code:

#![warn(clippy::use_self)]
#![allow(unused)]

pub enum Something {
    Empty,
    Num(u8),
    TupleNums(u8, u8),
    StructNums { one: u8, two: u8 },
}

impl Something {
    const fn get_value(&self) -> u8 {
        match self {
            Something::Empty => 0,
            Something::Num(n) => *n,                      
            Something::TupleNums(n, _m) => *n,            
            Something::StructNums { one, two: _ } => *one,
        }                                                 
    }                                                     
}                                                         

I expected to see this happen:

I should get a warning for all four uses of Something in get_value.

Instead, this happened:

I only get a warning for Something::Empty. Once I update it to Self::Empty I get no more warnings.

Version

rustc 1.61.0 (fe5b13d68 2022-05-18)
binary: rustc
commit-hash: fe5b13d681f25ee6474be29d748c65adcd91f69e
commit-date: 2022-05-18
host: x86_64-unknown-linux-gnu
release: 1.61.0
LLVM version: 14.0.0
@awused awused added C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't labels May 19, 2022
@carols10cents
Copy link
Member

Might be related to #6902 ?

bors bot pushed a commit to boa-dev/boa that referenced this issue May 20, 2022
This fixes the CI after the upgrade to Rust 1.61. I had to "allow" the `use_self` lint, due to rust-lang/rust-clippy#8845 and rust-lang/rust-clippy#6902.

It removed some false negatives, though, so I fixed some of the usage.
@botahamec
Copy link
Contributor

@rustbot claim

@bors bors closed this as completed in d9f4978 May 30, 2022
Razican added a commit to boa-dev/boa that referenced this issue Jun 8, 2022
This fixes the CI after the upgrade to Rust 1.61. I had to "allow" the `use_self` lint, due to rust-lang/rust-clippy#8845 and rust-lang/rust-clippy#6902.

It removed some false negatives, though, so I fixed some of the usage.
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 I-false-negative Issue: The lint should have been triggered on code, but wasn't
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants