11use clippy_utils:: attrs:: is_doc_hidden;
22use clippy_utils:: diagnostics:: span_lint_and_help;
33use clippy_utils:: is_path_lang_item;
4- // use rustc_ast::ast::{Item, ItemKind, VisibilityKind};
54use rustc_hir:: { FieldDef , Item , ItemKind , LangItem } ;
65use rustc_lint:: { LateContext , LateLintPass } ;
76use rustc_middle:: ty:: Visibility ;
@@ -31,7 +30,7 @@ declare_clippy_lint! {
3130 ///
3231 /// // OR
3332 ///
34- /// ```
33+ /// ```rust
3534 /// struct FileHandle {
3635 /// pub descriptor: usize,
3736 /// }
@@ -46,7 +45,7 @@ declare_lint_pass!(PubUnderscoreFields => [PUB_UNDERSCORE_FIELDS]);
4645impl < ' tcx > LateLintPass < ' tcx > for PubUnderscoreFields {
4746 fn check_item ( & mut self , cx : & LateContext < ' tcx > , item : & ' tcx Item < ' _ > ) {
4847 // This lint only pertains to structs.
49- let ItemKind :: Struct ( var , _) = & item. kind else {
48+ let ItemKind :: Struct ( variant_data , _) = & item. kind else {
5049 return ;
5150 } ;
5251
@@ -61,9 +60,9 @@ impl<'tcx> LateLintPass<'tcx> for PubUnderscoreFields {
6160 case_1 || case_2
6261 } ;
6362
64- for field in var . fields ( ) {
65- // Only pertains to fields that start with an underscore, and are visible publically .
66- if field. ident . as_str ( ) . starts_with ( '_' ) && is_visible ( & field)
63+ for field in variant_data . fields ( ) {
64+ // Only pertains to fields that start with an underscore, and are public .
65+ if field. ident . as_str ( ) . starts_with ( '_' ) && is_visible ( field)
6766 // We ignore fields that have `#[doc(hidden)]`.
6867 && !is_doc_hidden ( cx. tcx . hir ( ) . attrs ( field. hir_id ) )
6968 // We ignore fields that are `PhantomData`.
0 commit comments