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

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

Closed
xFrednet opened this issue Sep 17, 2023 · 2 comments · Fixed by #11523
Closed

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

xFrednet opened this issue Sep 17, 2023 · 2 comments · Fixed by #11523
Assignees
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages

Comments

@xFrednet
Copy link
Member

xFrednet commented Sep 17, 2023

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

@xFrednet xFrednet added good-first-issue These issues are a good way to get started with Clippy C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages labels Sep 17, 2023
@Alexendoo
Copy link
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

@Alexendoo Alexendoo removed the good-first-issue These issues are a good way to get started with Clippy label Sep 17, 2023
@Alexendoo Alexendoo self-assigned this Sep 17, 2023
@xFrednet
Copy link
Member Author

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

@bors bors closed this as completed in c92de58 Sep 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants