2
2
// *rustc*'s
3
3
// [`missing_doc`].
4
4
//
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
6
6
//
7
7
8
8
use crate :: utils:: span_lint;
@@ -70,7 +70,14 @@ impl MissingDoc {
70
70
}
71
71
}
72
72
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
+ ) {
74
81
// If we're building a test harness, then warning about
75
82
// documentation is probably not really relevant right now.
76
83
if cx. sess ( ) . opts . test {
@@ -94,7 +101,7 @@ impl MissingDoc {
94
101
cx,
95
102
MISSING_DOCS_IN_PRIVATE_ITEMS ,
96
103
sp,
97
- & format ! ( "missing documentation for {}" , desc) ,
104
+ & format ! ( "missing documentation for {} {}" , article , desc) ,
98
105
) ;
99
106
}
100
107
}
@@ -120,13 +127,11 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
120
127
}
121
128
122
129
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") ;
124
131
}
125
132
126
133
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 {
130
135
hir:: ItemKind :: Fn ( ..) => {
131
136
// ignore main()
132
137
if it. ident . name == sym:: main {
@@ -136,34 +141,35 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
136
141
return ;
137
142
}
138
143
}
139
- "a function"
140
144
} ,
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 ( ..) => { } ,
149
155
hir:: ItemKind :: ExternCrate ( ..)
150
156
| hir:: ItemKind :: ForeignMod { .. }
151
157
| hir:: ItemKind :: GlobalAsm ( ..)
152
158
| hir:: ItemKind :: Impl { .. }
153
159
| hir:: ItemKind :: Use ( ..) => return ,
154
160
} ;
155
161
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) ;
157
166
}
158
167
159
168
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 ( ) ) ;
165
171
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) ;
167
173
}
168
174
169
175
fn check_impl_item ( & mut self , cx : & LateContext < ' tcx > , impl_item : & ' tcx hir:: ImplItem < ' _ > ) {
@@ -178,21 +184,17 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
178
184
} ,
179
185
}
180
186
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) ;
187
189
}
188
190
189
191
fn check_struct_field ( & mut self , cx : & LateContext < ' tcx > , sf : & ' tcx hir:: StructField < ' _ > ) {
190
192
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") ;
192
194
}
193
195
}
194
196
195
197
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") ;
197
199
}
198
200
}
0 commit comments