Skip to content

Commit

Permalink
polish
Browse files Browse the repository at this point in the history
  • Loading branch information
ParkMyCar committed Oct 13, 2023
1 parent 6fb0fa0 commit 57b2ef6
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions clippy_lints/src/pub_underscore_fields.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use clippy_utils::attrs::is_doc_hidden;
use clippy_utils::diagnostics::span_lint_and_help;
use clippy_utils::is_path_lang_item;
// use rustc_ast::ast::{Item, ItemKind, VisibilityKind};
use rustc_hir::{FieldDef, Item, ItemKind, LangItem};
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::ty::Visibility;
Expand Down Expand Up @@ -31,7 +30,7 @@ declare_clippy_lint! {
///
/// // OR
///
/// ```
/// ```rust
/// struct FileHandle {
/// pub descriptor: usize,
/// }
Expand All @@ -46,7 +45,7 @@ declare_lint_pass!(PubUnderscoreFields => [PUB_UNDERSCORE_FIELDS]);
impl<'tcx> LateLintPass<'tcx> for PubUnderscoreFields {
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
// This lint only pertains to structs.
let ItemKind::Struct(var, _) = &item.kind else {
let ItemKind::Struct(variant_data, _) = &item.kind else {
return;
};

Expand All @@ -61,9 +60,9 @@ impl<'tcx> LateLintPass<'tcx> for PubUnderscoreFields {
case_1 || case_2
};

for field in var.fields() {
// Only pertains to fields that start with an underscore, and are visible publically.
if field.ident.as_str().starts_with('_') && is_visible(&field)
for field in variant_data.fields() {
// Only pertains to fields that start with an underscore, and are public.
if field.ident.as_str().starts_with('_') && is_visible(field)
// We ignore fields that have `#[doc(hidden)]`.
&& !is_doc_hidden(cx.tcx.hir().attrs(field.hir_id))
// We ignore fields that are `PhantomData`.
Expand Down

0 comments on commit 57b2ef6

Please sign in to comment.