@@ -2,11 +2,9 @@ use clippy_config::types::PubUnderscoreFieldsBehaviour;
22use clippy_utils:: attrs:: is_doc_hidden;
33use clippy_utils:: diagnostics:: span_lint_and_help;
44use clippy_utils:: is_path_lang_item;
5- use clippy_utils:: source:: snippet_opt;
65use rustc_hir:: { FieldDef , Item , ItemKind , LangItem } ;
76use rustc_lint:: { LateContext , LateLintPass } ;
87use rustc_session:: impl_lint_pass;
9- use rustc_span:: Span ;
108
119declare_clippy_lint ! {
1210 /// ### What it does
@@ -30,7 +28,7 @@ declare_clippy_lint! {
3028 /// }
3129 /// ```
3230 ///
33- /// // OR
31+ /// OR
3432 ///
3533 /// ```rust
3634 /// struct FileHandle {
@@ -57,7 +55,10 @@ impl<'tcx> LateLintPass<'tcx> for PubUnderscoreFields {
5755
5856 let is_visible = |field : & FieldDef < ' _ > | match self . behavior {
5957 PubUnderscoreFieldsBehaviour :: PublicallyExported => cx. effective_visibilities . is_reachable ( field. def_id ) ,
60- PubUnderscoreFieldsBehaviour :: AllPubFields => start_with_pub ( cx, field. vis_span ) ,
58+ PubUnderscoreFieldsBehaviour :: AllPubFields => {
59+ // If there is a visibility span then the field is marked pub in some way.
60+ !field. vis_span . is_empty ( )
61+ } ,
6162 } ;
6263
6364 for field in variant_data. fields ( ) {
@@ -80,9 +81,3 @@ impl<'tcx> LateLintPass<'tcx> for PubUnderscoreFields {
8081 }
8182 }
8283}
83-
84- fn start_with_pub ( cx : & LateContext < ' _ > , span : Span ) -> bool {
85- snippet_opt ( cx, span)
86- . map ( |s| s. as_str ( ) . starts_with ( "pub" ) )
87- . unwrap_or ( false )
88- }
0 commit comments