@@ -2,11 +2,9 @@ use clippy_config::types::PubUnderscoreFieldsBehaviour;
2
2
use clippy_utils:: attrs:: is_doc_hidden;
3
3
use clippy_utils:: diagnostics:: span_lint_and_help;
4
4
use clippy_utils:: is_path_lang_item;
5
- use clippy_utils:: source:: snippet_opt;
6
5
use rustc_hir:: { FieldDef , Item , ItemKind , LangItem } ;
7
6
use rustc_lint:: { LateContext , LateLintPass } ;
8
7
use rustc_session:: impl_lint_pass;
9
- use rustc_span:: Span ;
10
8
11
9
declare_clippy_lint ! {
12
10
/// ### What it does
@@ -30,7 +28,7 @@ declare_clippy_lint! {
30
28
/// }
31
29
/// ```
32
30
///
33
- /// // OR
31
+ /// OR
34
32
///
35
33
/// ```rust
36
34
/// struct FileHandle {
@@ -57,7 +55,10 @@ impl<'tcx> LateLintPass<'tcx> for PubUnderscoreFields {
57
55
58
56
let is_visible = |field : & FieldDef < ' _ > | match self . behavior {
59
57
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
+ } ,
61
62
} ;
62
63
63
64
for field in variant_data. fields ( ) {
@@ -80,9 +81,3 @@ impl<'tcx> LateLintPass<'tcx> for PubUnderscoreFields {
80
81
}
81
82
}
82
83
}
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