Skip to content

Commit

Permalink
github feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
ParkMyCar committed Dec 27, 2023
1 parent 0d85ac1 commit ea82130
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions clippy_lints/src/pub_underscore_fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ use clippy_config::types::PubUnderscoreFieldsBehaviour;
use clippy_utils::attrs::is_doc_hidden;
use clippy_utils::diagnostics::span_lint_and_help;
use clippy_utils::is_path_lang_item;
use clippy_utils::source::snippet_opt;
use rustc_hir::{FieldDef, Item, ItemKind, LangItem};
use rustc_lint::{LateContext, LateLintPass};
use rustc_session::impl_lint_pass;
use rustc_span::Span;

declare_clippy_lint! {
/// ### What it does
Expand All @@ -30,7 +28,7 @@ declare_clippy_lint! {
/// }
/// ```
///
/// // OR
/// OR
///
/// ```rust
/// struct FileHandle {
Expand All @@ -57,7 +55,10 @@ impl<'tcx> LateLintPass<'tcx> for PubUnderscoreFields {

let is_visible = |field: &FieldDef<'_>| match self.behavior {
PubUnderscoreFieldsBehaviour::PublicallyExported => cx.effective_visibilities.is_reachable(field.def_id),
PubUnderscoreFieldsBehaviour::AllPubFields => start_with_pub(cx, field.vis_span),
PubUnderscoreFieldsBehaviour::AllPubFields => {
// If there is a visibility span then the field is marked pub in some way.
!field.vis_span.is_empty()
},
};

for field in variant_data.fields() {
Expand All @@ -80,9 +81,3 @@ impl<'tcx> LateLintPass<'tcx> for PubUnderscoreFields {
}
}
}

fn start_with_pub(cx: &LateContext<'_>, span: Span) -> bool {
snippet_opt(cx, span)
.map(|s| s.as_str().starts_with("pub"))
.unwrap_or(false)
}

0 comments on commit ea82130

Please sign in to comment.