22// *rustc*'s
33// [`missing_doc`].
44//
5- // [`missing_doc`]: https://github.com/rust-lang/rust/blob/d6d05904697d89099b55da3331155392f1db9c00/src/librustc_lint/ builtin.rs#L246
5+ // [`missing_doc`]: https://github.com/rust-lang/rust/blob/cf9cf7c923eb01146971429044f216a3ca905e06/compiler/rustc_lint/src/ builtin.rs#L415
66//
77
88use crate :: utils:: span_lint;
@@ -70,7 +70,14 @@ impl MissingDoc {
7070 }
7171 }
7272
73- fn check_missing_docs_attrs ( & self , cx : & LateContext < ' _ > , attrs : & [ ast:: Attribute ] , sp : Span , desc : & ' static str ) {
73+ fn check_missing_docs_attrs (
74+ & self ,
75+ cx : & LateContext < ' _ > ,
76+ attrs : & [ ast:: Attribute ] ,
77+ sp : Span ,
78+ article : & ' static str ,
79+ desc : & ' static str ,
80+ ) {
7481 // If we're building a test harness, then warning about
7582 // documentation is probably not really relevant right now.
7683 if cx. sess ( ) . opts . test {
@@ -94,7 +101,7 @@ impl MissingDoc {
94101 cx,
95102 MISSING_DOCS_IN_PRIVATE_ITEMS ,
96103 sp,
97- & format ! ( "missing documentation for {}" , desc) ,
104+ & format ! ( "missing documentation for {} {}" , article , desc) ,
98105 ) ;
99106 }
100107 }
@@ -120,13 +127,11 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
120127 }
121128
122129 fn check_crate ( & mut self , cx : & LateContext < ' tcx > , krate : & ' tcx hir:: Crate < ' _ > ) {
123- self . check_missing_docs_attrs ( cx, & krate. item . attrs , krate. item . span , "crate" ) ;
130+ self . check_missing_docs_attrs ( cx, & krate. item . attrs , krate. item . span , "the" , " crate") ;
124131 }
125132
126133 fn check_item ( & mut self , cx : & LateContext < ' tcx > , it : & ' tcx hir:: Item < ' _ > ) {
127- let desc = match it. kind {
128- hir:: ItemKind :: Const ( ..) => "a constant" ,
129- hir:: ItemKind :: Enum ( ..) => "an enum" ,
134+ match it. kind {
130135 hir:: ItemKind :: Fn ( ..) => {
131136 // ignore main()
132137 if it. ident . name == sym:: main {
@@ -136,34 +141,35 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
136141 return ;
137142 }
138143 }
139- "a function"
140144 } ,
141- hir:: ItemKind :: Mod ( ..) => "a module" ,
142- hir:: ItemKind :: Static ( ..) => "a static" ,
143- hir:: ItemKind :: Struct ( ..) => "a struct" ,
144- hir:: ItemKind :: Trait ( ..) => "a trait" ,
145- hir:: ItemKind :: TraitAlias ( ..) => "a trait alias" ,
146- hir:: ItemKind :: TyAlias ( ..) => "a type alias" ,
147- hir:: ItemKind :: Union ( ..) => "a union" ,
148- hir:: ItemKind :: OpaqueTy ( ..) => "an existential type" ,
145+ hir:: ItemKind :: Const ( ..)
146+ | hir:: ItemKind :: Enum ( ..)
147+ | hir:: ItemKind :: Mod ( ..)
148+ | hir:: ItemKind :: Static ( ..)
149+ | hir:: ItemKind :: Struct ( ..)
150+ | hir:: ItemKind :: Trait ( ..)
151+ | hir:: ItemKind :: TraitAlias ( ..)
152+ | hir:: ItemKind :: TyAlias ( ..)
153+ | hir:: ItemKind :: Union ( ..)
154+ | hir:: ItemKind :: OpaqueTy ( ..) => { } ,
149155 hir:: ItemKind :: ExternCrate ( ..)
150156 | hir:: ItemKind :: ForeignMod { .. }
151157 | hir:: ItemKind :: GlobalAsm ( ..)
152158 | hir:: ItemKind :: Impl { .. }
153159 | hir:: ItemKind :: Use ( ..) => return ,
154160 } ;
155161
156- self . check_missing_docs_attrs ( cx, & it. attrs , it. span , desc) ;
162+ let def_id = cx. tcx . hir ( ) . local_def_id ( it. hir_id ) ;
163+ let ( article, desc) = cx. tcx . article_and_description ( def_id. to_def_id ( ) ) ;
164+
165+ self . check_missing_docs_attrs ( cx, & it. attrs , it. span , article, desc) ;
157166 }
158167
159168 fn check_trait_item ( & mut self , cx : & LateContext < ' tcx > , trait_item : & ' tcx hir:: TraitItem < ' _ > ) {
160- let desc = match trait_item. kind {
161- hir:: TraitItemKind :: Const ( ..) => "an associated constant" ,
162- hir:: TraitItemKind :: Fn ( ..) => "a trait method" ,
163- hir:: TraitItemKind :: Type ( ..) => "an associated type" ,
164- } ;
169+ let def_id = cx. tcx . hir ( ) . local_def_id ( trait_item. hir_id ) ;
170+ let ( article, desc) = cx. tcx . article_and_description ( def_id. to_def_id ( ) ) ;
165171
166- self . check_missing_docs_attrs ( cx, & trait_item. attrs , trait_item. span , desc) ;
172+ self . check_missing_docs_attrs ( cx, & trait_item. attrs , trait_item. span , article , desc) ;
167173 }
168174
169175 fn check_impl_item ( & mut self , cx : & LateContext < ' tcx > , impl_item : & ' tcx hir:: ImplItem < ' _ > ) {
@@ -178,21 +184,17 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
178184 } ,
179185 }
180186
181- let desc = match impl_item. kind {
182- hir:: ImplItemKind :: Const ( ..) => "an associated constant" ,
183- hir:: ImplItemKind :: Fn ( ..) => "a method" ,
184- hir:: ImplItemKind :: TyAlias ( _) => "an associated type" ,
185- } ;
186- self . check_missing_docs_attrs ( cx, & impl_item. attrs , impl_item. span , desc) ;
187+ let ( article, desc) = cx. tcx . article_and_description ( def_id. to_def_id ( ) ) ;
188+ self . check_missing_docs_attrs ( cx, & impl_item. attrs , impl_item. span , article, desc) ;
187189 }
188190
189191 fn check_struct_field ( & mut self , cx : & LateContext < ' tcx > , sf : & ' tcx hir:: StructField < ' _ > ) {
190192 if !sf. is_positional ( ) {
191- self . check_missing_docs_attrs ( cx, & sf. attrs , sf. span , "a struct field" ) ;
193+ self . check_missing_docs_attrs ( cx, & sf. attrs , sf. span , "a" , " struct field") ;
192194 }
193195 }
194196
195197 fn check_variant ( & mut self , cx : & LateContext < ' tcx > , v : & ' tcx hir:: Variant < ' _ > ) {
196- self . check_missing_docs_attrs ( cx, & v. attrs , v. span , "a variant" ) ;
198+ self . check_missing_docs_attrs ( cx, & v. attrs , v. span , "a" , " variant") ;
197199 }
198200}
0 commit comments