Skip to content

Check if clippy::used_underscore_binding is allowed on the underscore field #11520

@xFrednet

Description

@xFrednet
Member

Description

It would be cool, if the clippy::used_underscore_binding lint would also check the lint level at the field itself. This would make it simple to allow the lint, if it's used by a derive macro

Example

#![warn(clippy::used_underscore_binding)]

pub struct Bar {
    // This allow should also suppress the lint
    // vvv
    #[allow(clippy::used_underscore_binding)]
    _cool: u32,
}

impl Bar {
    pub fn something(&self) {
        println!("{}", self._cool);
    } 
}

Hints:

The lint level at a given note, can be checked with TyCtxt::lint_level_at_node accessed via cx.tcx.lint_level_at_node with the HirId of the field. If the level is Level::Expect, the expectation should be marked as fulfilled by calling LateContext::fulfill_expectation

Version

1.74.0

Additional Information

Context: idanarye/rust-typed-builder#113

Activity

added
good first issueThese issues are a good way to get started with Clippy
C-enhancementCategory: Enhancement of lints, like adding more cases or adding help messages
on Sep 17, 2023
Alexendoo

Alexendoo commented on Sep 17, 2023

@Alexendoo
Member

Ignoring phantom data fields is probably also reasonable. I'll take a stab at this one, might be a little tricky to get to the field definition from the usage site

removed
good first issueThese issues are a good way to get started with Clippy
on Sep 17, 2023
self-assigned this
on Sep 17, 2023
xFrednet

xFrednet commented on Sep 17, 2023

@xFrednet
MemberAuthor

You should be able to get the type of self and then fetch the struct definition with field information from that. And you just created a PR xD

added a commit that references this issue on Sep 18, 2023
c92de58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

C-enhancementCategory: Enhancement of lints, like adding more cases or adding help messages

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Participants

    @Alexendoo@xFrednet

    Issue actions

      Check if `clippy::used_underscore_binding` is allowed on the underscore field · Issue #11520 · rust-lang/rust-clippy