Skip to content

Warnings for missing documentations. #6715

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 27, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions src/librustc/middle/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ pub enum lint {
dead_assignment,
unused_mut,
unnecessary_allocation,

missing_struct_doc,
missing_trait_doc,
}

pub fn level_to_str(lv: level) -> &'static str {
Expand Down Expand Up @@ -252,6 +255,20 @@ static lint_table: &'static [(&'static str, LintSpec)] = &[
desc: "detects unnecessary allocations that can be eliminated",
default: warn
}),

("missing_struct_doc",
LintSpec {
lint: missing_struct_doc,
desc: "detects missing documentation for structs",
default: allow
}),

("missing_trait_doc",
LintSpec {
lint: missing_trait_doc,
desc: "detects missing documentation for traits",
default: allow
}),
];

/*
Expand Down Expand Up @@ -952,6 +969,69 @@ fn lint_unnecessary_allocations(cx: @mut Context) -> visit::vt<()> {
})
}

fn lint_missing_struct_doc(cx: @mut Context) -> visit::vt<()> {
visit::mk_simple_visitor(@visit::SimpleVisitor {
visit_struct_field: |field| {
let relevant = match field.node.kind {
ast::named_field(_, vis) => vis != ast::private,
ast::unnamed_field => false,
};

if relevant {
let mut has_doc = false;
for field.node.attrs.each |attr| {
if attr.node.is_sugared_doc {
has_doc = true;
break;
}
}
if !has_doc {
cx.span_lint(missing_struct_doc, field.span, "missing documentation \
for a field.");
}
}
},
.. *visit::default_simple_visitor()
})
}

fn lint_missing_trait_doc(cx: @mut Context) -> visit::vt<()> {
visit::mk_simple_visitor(@visit::SimpleVisitor {
visit_trait_method: |method| {
let mut has_doc = false;
let span = match copy *method {
ast::required(m) => {
for m.attrs.each |attr| {
if attr.node.is_sugared_doc {
has_doc = true;
break;
}
}
m.span
},
ast::provided(m) => {
if m.vis == ast::private {
has_doc = true;
} else {
for m.attrs.each |attr| {
if attr.node.is_sugared_doc {
has_doc = true;
break;
}
}
}
m.span
}
};
if !has_doc {
cx.span_lint(missing_trait_doc, span, "missing documentation \
for a method.");
}
},
.. *visit::default_simple_visitor()
})
}

pub fn check_crate(tcx: ty::ctxt, crate: @ast::crate) {
let cx = @mut Context {
dict: @get_lint_dict(),
Expand Down Expand Up @@ -980,6 +1060,8 @@ pub fn check_crate(tcx: ty::ctxt, crate: @ast::crate) {
cx.add_lint(lint_unused_mut(cx));
cx.add_lint(lint_session(cx));
cx.add_lint(lint_unnecessary_allocations(cx));
cx.add_lint(lint_missing_struct_doc(cx));
cx.add_lint(lint_missing_trait_doc(cx));

// type inference doesn't like this being declared below, we need to tell it
// what the type of this first function is...
Expand Down