@@ -1048,7 +1048,7 @@ fn check_unnecessary_allocation(cx: &Context, e: &ast::Expr) {
10481048}
10491049
10501050fn check_missing_doc_attrs ( cx : & Context ,
1051- id : ast:: NodeId ,
1051+ id : Option < ast:: NodeId > ,
10521052 attrs : & [ ast:: Attribute ] ,
10531053 sp : Span ,
10541054 desc : & ' static str ) {
@@ -1059,17 +1059,20 @@ fn check_missing_doc_attrs(cx: &Context,
10591059 // `#[doc(hidden)]` disables missing_doc check.
10601060 if cx. is_doc_hidden { return }
10611061
1062- // Only check publicly-visible items, using the result from the
1063- // privacy pass.
1064- if !cx. exported_items . contains ( & id) { return }
1062+ // Only check publicly-visible items, using the result from the privacy pass. It's an option so
1063+ // the crate root can also use this function (it doesn't have a NodeId).
1064+ match id {
1065+ Some ( ref id) if !cx. exported_items . contains ( id) => return ,
1066+ _ => ( )
1067+ }
10651068
10661069 if !attrs. iter ( ) . any ( |a| a. node . is_sugared_doc ) {
10671070 cx. span_lint ( missing_doc, sp,
10681071 format ! ( "missing documentation for {}" , desc) ) ;
10691072 }
10701073}
10711074
1072- fn check_missing_doc_item ( cx : & mut Context , it : & ast:: item ) { // XXX doesn't need to be mut
1075+ fn check_missing_doc_item ( cx : & Context , it : & ast:: item ) {
10731076 let desc = match it. node {
10741077 ast:: item_fn( ..) => "a function" ,
10751078 ast:: item_mod( ..) => "a module" ,
@@ -1078,7 +1081,7 @@ fn check_missing_doc_item(cx: &mut Context, it: &ast::item) { // XXX doesn't nee
10781081 ast:: item_trait( ..) => "a trait" ,
10791082 _ => return
10801083 } ;
1081- check_missing_doc_attrs ( cx, it. id , it. attrs , it. span , desc) ;
1084+ check_missing_doc_attrs ( cx, Some ( it. id ) , it. attrs , it. span , desc) ;
10821085}
10831086
10841087fn check_missing_doc_method ( cx : & Context , m : & ast:: method ) {
@@ -1104,24 +1107,24 @@ fn check_missing_doc_method(cx: &Context, m: &ast::method) {
11041107 }
11051108 }
11061109 }
1107- check_missing_doc_attrs ( cx, m. id , m. attrs , m. span , "a method" ) ;
1110+ check_missing_doc_attrs ( cx, Some ( m. id ) , m. attrs , m. span , "a method" ) ;
11081111}
11091112
11101113fn check_missing_doc_ty_method ( cx : & Context , tm : & ast:: TypeMethod ) {
1111- check_missing_doc_attrs ( cx, tm. id , tm. attrs , tm. span , "a type method" ) ;
1114+ check_missing_doc_attrs ( cx, Some ( tm. id ) , tm. attrs , tm. span , "a type method" ) ;
11121115}
11131116
11141117fn check_missing_doc_struct_field ( cx : & Context , sf : & ast:: struct_field ) {
11151118 match sf. node . kind {
11161119 ast:: named_field( _, vis) if vis != ast:: private =>
1117- check_missing_doc_attrs ( cx, cx. cur_struct_def_id , sf. node . attrs ,
1120+ check_missing_doc_attrs ( cx, Some ( cx. cur_struct_def_id ) , sf. node . attrs ,
11181121 sf. span , "a struct field" ) ,
11191122 _ => { }
11201123 }
11211124}
11221125
11231126fn check_missing_doc_variant ( cx : & Context , v : & ast:: variant ) {
1124- check_missing_doc_attrs ( cx, v. node . id , v. node . attrs , v. span , "a variant" ) ;
1127+ check_missing_doc_attrs ( cx, Some ( v. node . id ) , v. node . attrs , v. span , "a variant" ) ;
11251128}
11261129
11271130/// Checks for use of items with #[deprecated], #[experimental] and
@@ -1372,6 +1375,9 @@ pub fn check_crate(tcx: ty::ctxt,
13721375 } ) ;
13731376
13741377 check_crate_attrs_usage ( cx, crate . attrs) ;
1378+ // since the root module isn't visited as an item (because it isn't an item), warn for it
1379+ // here.
1380+ check_missing_doc_attrs ( cx, None , crate . attrs, crate . span, "crate" ) ;
13751381
13761382 visit:: walk_crate ( cx, crate , ( ) ) ;
13771383 } ) ;
0 commit comments