-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Closed
Copy link
Labels
C-enhancementCategory: Enhancement of lints, like adding more cases or adding help messagesCategory: Enhancement of lints, like adding more cases or adding help messages
Description
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
Metadata
Metadata
Assignees
Labels
C-enhancementCategory: Enhancement of lints, like adding more cases or adding help messagesCategory: Enhancement of lints, like adding more cases or adding help messages
Activity
Alexendoo commentedon Sep 17, 2023
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
xFrednet commentedon Sep 17, 2023
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
Auto merge of #11523 - Alexendoo:used-underscore-bindings-lint-levels…