diff --git a/clippy_lints/src/pub_underscore_fields.rs b/clippy_lints/src/pub_underscore_fields.rs index 21a7b46d6b02..2bf738f3816e 100644 --- a/clippy_lints/src/pub_underscore_fields.rs +++ b/clippy_lints/src/pub_underscore_fields.rs @@ -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 @@ -30,7 +28,7 @@ declare_clippy_lint! { /// } /// ``` /// - /// // OR + /// OR /// /// ```rust /// struct FileHandle { @@ -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() { @@ -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) -}