@@ -82,6 +82,9 @@ pub enum lint {
82
82
dead_assignment,
83
83
unused_mut,
84
84
unnecessary_allocation,
85
+
86
+ missing_struct_doc,
87
+ missing_trait_doc,
85
88
}
86
89
87
90
pub fn level_to_str ( lv : level ) -> & ' static str {
@@ -252,6 +255,20 @@ static lint_table: &'static [(&'static str, LintSpec)] = &[
252
255
desc : "detects unnecessary allocations that can be eliminated" ,
253
256
default : warn
254
257
} ) ,
258
+
259
+ ( "missing_struct_doc" ,
260
+ LintSpec {
261
+ lint : missing_struct_doc,
262
+ desc : "detects missing documentation for structs" ,
263
+ default : allow
264
+ } ) ,
265
+
266
+ ( "missing_trait_doc" ,
267
+ LintSpec {
268
+ lint : missing_trait_doc,
269
+ desc : "detects missing documentation for traits" ,
270
+ default : allow
271
+ } ) ,
255
272
] ;
256
273
257
274
/*
@@ -952,6 +969,58 @@ fn lint_unnecessary_allocations(cx: @mut Context) -> visit::vt<()> {
952
969
} )
953
970
}
954
971
972
+ fn lint_missing_struct_doc( cx: @mut Context ) -> visit:: vt<( ) > {
973
+ visit:: mk_simple_visitor ( @visit:: SimpleVisitor {
974
+ visit_struct_field : |field| {
975
+ let mut has_doc = false ;
976
+ for field. node. attrs. each |attr| {
977
+ if attr. node . is_sugared_doc {
978
+ has_doc = true ;
979
+ break ;
980
+ }
981
+ }
982
+ if !has_doc {
983
+ cx. span_lint ( missing_struct_doc, field. span , "missing documentation \
984
+ for a field.") ;
985
+ }
986
+ } ,
987
+ .. * visit:: default_simple_visitor ( )
988
+ } )
989
+ }
990
+
991
+ fn lint_missing_trait_doc( cx: @mut Context ) -> visit:: vt<( ) > {
992
+ visit:: mk_simple_visitor ( @visit:: SimpleVisitor {
993
+ visit_trait_method : |method| {
994
+ let mut has_doc = false ;
995
+ let span = match copy * method {
996
+ ast:: required( m) => {
997
+ for m. attrs. each |attr| {
998
+ if attr. node . is_sugared_doc {
999
+ has_doc = true ;
1000
+ break ;
1001
+ }
1002
+ }
1003
+ m. span
1004
+ } ,
1005
+ ast:: provided( m) => {
1006
+ for m. attrs. each |attr| {
1007
+ if attr. node . is_sugared_doc {
1008
+ has_doc = true ;
1009
+ break ;
1010
+ }
1011
+ }
1012
+ m. span
1013
+ }
1014
+ } ;
1015
+ if !has_doc {
1016
+ cx. span_lint ( missing_trait_doc, span, "missing documentation \
1017
+ for a method.") ;
1018
+ }
1019
+ } ,
1020
+ .. * visit:: default_simple_visitor ( )
1021
+ } )
1022
+ }
1023
+
955
1024
pub fn check_crate( tcx: ty:: ctxt, crate : @ast:: crate) {
956
1025
let cx = @mut Context {
957
1026
dict : @get_lint_dict ( ) ,
@@ -980,6 +1049,8 @@ pub fn check_crate(tcx: ty::ctxt, crate: @ast::crate) {
980
1049
cx. add_lint ( lint_unused_mut ( cx) ) ;
981
1050
cx. add_lint ( lint_session ( cx) ) ;
982
1051
cx. add_lint ( lint_unnecessary_allocations ( cx) ) ;
1052
+ cx. add_lint ( lint_missing_struct_doc ( cx) ) ;
1053
+ cx. add_lint ( lint_missing_trait_doc ( cx) ) ;
983
1054
984
1055
// type inference doesn't like this being declared below, we need to tell it
985
1056
// what the type of this first function is...
0 commit comments