@@ -4,8 +4,10 @@ use crate::fold::{self, DocFolder};
4
4
use crate :: html:: markdown:: { find_testable_code, ErrorCodes } ;
5
5
use crate :: passes:: doc_test_lints:: { should_have_doc_example, Tests } ;
6
6
use crate :: passes:: Pass ;
7
+ use rustc_hir as hir;
7
8
use rustc_lint:: builtin:: MISSING_DOCS ;
8
9
use rustc_middle:: lint:: LintLevelSource ;
10
+ use rustc_middle:: ty:: DefIdTree ;
9
11
use rustc_session:: lint;
10
12
use rustc_span:: FileName ;
11
13
use serde:: Serialize ;
@@ -221,10 +223,42 @@ impl<'a, 'b> fold::DocFolder for CoverageCalculator<'a, 'b> {
221
223
. hir ( )
222
224
. local_def_id_to_hir_id ( i. def_id . expect_def_id ( ) . expect_local ( ) ) ;
223
225
let ( level, source) = self . ctx . tcx . lint_level_at_node ( MISSING_DOCS , hir_id) ;
226
+
227
+ // In case we have:
228
+ //
229
+ // ```
230
+ // enum Foo { Bar(u32) }
231
+ // // or:
232
+ // struct Bar(u32);
233
+ // ```
234
+ //
235
+ // there is no need to require documentation on the fields of tuple variants and
236
+ // tuple structs.
237
+ let should_be_ignored = i
238
+ . def_id
239
+ . as_def_id ( )
240
+ . and_then ( |def_id| self . ctx . tcx . parent ( def_id) )
241
+ . and_then ( |def_id| self . ctx . tcx . hir ( ) . get_if_local ( def_id) )
242
+ . map ( |node| {
243
+ matches ! (
244
+ node,
245
+ hir:: Node :: Variant ( hir:: Variant {
246
+ data: hir:: VariantData :: Tuple ( _, _) ,
247
+ ..
248
+ } ) | hir:: Node :: Item ( hir:: Item {
249
+ kind: hir:: ItemKind :: Struct ( hir:: VariantData :: Tuple ( _, _) , _) ,
250
+ ..
251
+ } )
252
+ )
253
+ } )
254
+ . unwrap_or ( false ) ;
255
+
224
256
// `missing_docs` is allow-by-default, so don't treat this as ignoring the item
225
- // unless the user had an explicit `allow`
226
- let should_have_docs =
227
- level != lint:: Level :: Allow || matches ! ( source, LintLevelSource :: Default ) ;
257
+ // unless the user had an explicit `allow`.
258
+ //
259
+ let should_have_docs = !should_be_ignored
260
+ && ( level != lint:: Level :: Allow || matches ! ( source, LintLevelSource :: Default ) ) ;
261
+
228
262
debug ! ( "counting {:?} {:?} in {:?}" , i. type_( ) , i. name, filename) ;
229
263
self . items . entry ( filename) . or_default ( ) . count_item (
230
264
has_docs,
0 commit comments