Skip to content

use_self false negative on tuple or struct enum variants #8845

@awused

Description

@awused

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 

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn't

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions