@@ -1048,7 +1048,7 @@ fn check_unnecessary_allocation(cx: &Context, e: &ast::Expr) {
1048
1048
}
1049
1049
1050
1050
fn check_missing_doc_attrs ( cx : & Context ,
1051
- id : ast:: NodeId ,
1051
+ id : Option < ast:: NodeId > ,
1052
1052
attrs : & [ ast:: Attribute ] ,
1053
1053
sp : Span ,
1054
1054
desc : & ' static str ) {
@@ -1059,17 +1059,20 @@ fn check_missing_doc_attrs(cx: &Context,
1059
1059
// `#[doc(hidden)]` disables missing_doc check.
1060
1060
if cx. is_doc_hidden { return }
1061
1061
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
+ }
1065
1068
1066
1069
if !attrs. iter ( ) . any ( |a| a. node . is_sugared_doc ) {
1067
1070
cx. span_lint ( missing_doc, sp,
1068
1071
format ! ( "missing documentation for {}" , desc) ) ;
1069
1072
}
1070
1073
}
1071
1074
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 ) {
1073
1076
let desc = match it. node {
1074
1077
ast:: item_fn( ..) => "a function" ,
1075
1078
ast:: item_mod( ..) => "a module" ,
@@ -1078,7 +1081,7 @@ fn check_missing_doc_item(cx: &mut Context, it: &ast::item) { // XXX doesn't nee
1078
1081
ast:: item_trait( ..) => "a trait" ,
1079
1082
_ => return
1080
1083
} ;
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) ;
1082
1085
}
1083
1086
1084
1087
fn check_missing_doc_method ( cx : & Context , m : & ast:: method ) {
@@ -1104,24 +1107,24 @@ fn check_missing_doc_method(cx: &Context, m: &ast::method) {
1104
1107
}
1105
1108
}
1106
1109
}
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" ) ;
1108
1111
}
1109
1112
1110
1113
fn 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" ) ;
1112
1115
}
1113
1116
1114
1117
fn check_missing_doc_struct_field ( cx : & Context , sf : & ast:: struct_field ) {
1115
1118
match sf. node . kind {
1116
1119
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 ,
1118
1121
sf. span , "a struct field" ) ,
1119
1122
_ => { }
1120
1123
}
1121
1124
}
1122
1125
1123
1126
fn 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" ) ;
1125
1128
}
1126
1129
1127
1130
/// Checks for use of items with #[deprecated], #[experimental] and
@@ -1372,6 +1375,9 @@ pub fn check_crate(tcx: ty::ctxt,
1372
1375
} ) ;
1373
1376
1374
1377
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" ) ;
1375
1381
1376
1382
visit:: walk_crate ( cx, crate , ( ) ) ;
1377
1383
} ) ;
0 commit comments