Skip to content

Commit 5a50481

Browse files
committed
Auto merge of rust-lang#12309 - Tyrubias:fix-allow-pub-under, r=y21
fix: make `#[allow]` work on field for `pub_underscore_fields` Closes rust-lang#12286 changelog: `#[allow(clippy::pub_underscore_fields)]` now works on linted field
2 parents 5471e06 + d1e8a59 commit 5a50481

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

clippy_lints/src/pub_underscore_fields.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clippy_config::types::PubUnderscoreFieldsBehaviour;
22
use clippy_utils::attrs::is_doc_hidden;
3-
use clippy_utils::diagnostics::span_lint_and_help;
3+
use clippy_utils::diagnostics::span_lint_hir_and_then;
44
use clippy_utils::is_path_lang_item;
55
use rustc_hir::{FieldDef, Item, ItemKind, LangItem};
66
use rustc_lint::{LateContext, LateLintPass};
@@ -69,13 +69,15 @@ impl<'tcx> LateLintPass<'tcx> for PubUnderscoreFields {
6969
// We ignore fields that are `PhantomData`.
7070
&& !is_path_lang_item(cx, field.ty, LangItem::PhantomData)
7171
{
72-
span_lint_and_help(
72+
span_lint_hir_and_then(
7373
cx,
7474
PUB_UNDERSCORE_FIELDS,
75+
field.hir_id,
7576
field.vis_span.to(field.ident.span),
7677
"field marked as public but also inferred as unused because it's prefixed with `_`",
77-
None,
78-
"consider removing the underscore, or making the field private",
78+
|diag| {
79+
diag.help("consider removing the underscore, or making the field private");
80+
},
7981
);
8082
}
8183
}

tests/ui-toml/pub_underscore_fields/pub_underscore_fields.rs

+6
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,10 @@ fn main() {
6363
_pub: String,
6464
pub(crate) _mark: PhantomData<u8>,
6565
}
66+
67+
// shouldn't warn when `#[allow]` is used on field level
68+
pub struct AllowedViolations {
69+
#[allow(clippy::pub_underscore_fields)]
70+
pub _first: u32,
71+
}
6672
}

0 commit comments

Comments
 (0)