@@ -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
/*
@@ -931,6 +948,69 @@ fn lint_unnecessary_allocations(cx: @mut Context) -> visit::vt<()> {
931
948
} )
932
949
}
933
950
951
+ fn lint_missing_struct_doc( cx: @mut Context ) -> visit:: vt<( ) > {
952
+ visit:: mk_simple_visitor ( @visit:: SimpleVisitor {
953
+ visit_struct_field : |field| {
954
+ let relevant = match field. node . kind {
955
+ ast:: named_field( _, vis) => vis != ast:: private,
956
+ ast:: unnamed_field => false ,
957
+ } ;
958
+
959
+ if relevant {
960
+ let mut has_doc = false ;
961
+ for field. node. attrs. each |attr| {
962
+ if attr. node . is_sugared_doc {
963
+ has_doc = true ;
964
+ break ;
965
+ }
966
+ }
967
+ if !has_doc {
968
+ cx. span_lint ( missing_struct_doc, field. span , "missing documentation \
969
+ for a field.") ;
970
+ }
971
+ }
972
+ } ,
973
+ .. * visit:: default_simple_visitor ( )
974
+ } )
975
+ }
976
+
977
+ fn lint_missing_trait_doc( cx: @mut Context ) -> visit:: vt<( ) > {
978
+ visit:: mk_simple_visitor( @visit:: SimpleVisitor {
979
+ visit_trait_method: |method| {
980
+ let mut has_doc = false ;
981
+ let span = match copy * method {
982
+ ast:: required( m) => {
983
+ for m. attrs. each |attr| {
984
+ if attr. node . is_sugared_doc {
985
+ has_doc = true ;
986
+ break ;
987
+ }
988
+ }
989
+ m. span
990
+ } ,
991
+ ast:: provided( m) => {
992
+ if m. vis == ast:: private {
993
+ has_doc = true ;
994
+ } else {
995
+ for m. attrs . each |attr| {
996
+ if attr. node . is_sugared_doc {
997
+ has_doc = true ;
998
+ break ;
999
+ }
1000
+ }
1001
+ }
1002
+ m. span
1003
+ }
1004
+ } ;
1005
+ if !has_doc {
1006
+ cx. span_lint ( missing_trait_doc, span, "missing documentation \
1007
+ for a method.") ;
1008
+ }
1009
+ } ,
1010
+ .. * visit:: default_simple_visitor ( )
1011
+ } )
1012
+ }
1013
+
934
1014
pub fn check_crate( tcx: ty:: ctxt, crate : @ast:: crate) {
935
1015
let cx = @mut Context {
936
1016
dict : @get_lint_dict ( ) ,
@@ -959,6 +1039,8 @@ pub fn check_crate(tcx: ty::ctxt, crate: @ast::crate) {
959
1039
cx. add_lint ( lint_unused_mut ( cx) ) ;
960
1040
cx. add_lint ( lint_session ( cx) ) ;
961
1041
cx. add_lint ( lint_unnecessary_allocations ( cx) ) ;
1042
+ cx. add_lint ( lint_missing_struct_doc ( cx) ) ;
1043
+ cx. add_lint ( lint_missing_trait_doc ( cx) ) ;
962
1044
963
1045
// type inference doesn't like this being declared below, we need to tell it
964
1046
// what the type of this first function is...
0 commit comments