Skip to content
Closed
Show file tree
Hide file tree
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
26 changes: 16 additions & 10 deletions src/librustc/middle/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,7 @@ fn check_unnecessary_allocation(cx: &Context, e: &ast::Expr) {
}

fn check_missing_doc_attrs(cx: &Context,
id: ast::NodeId,
id: Option<ast::NodeId>,
attrs: &[ast::Attribute],
sp: Span,
desc: &'static str) {
Expand All @@ -1059,17 +1059,20 @@ fn check_missing_doc_attrs(cx: &Context,
// `#[doc(hidden)]` disables missing_doc check.
if cx.is_doc_hidden { return }

// Only check publicly-visible items, using the result from the
// privacy pass.
if !cx.exported_items.contains(&id) { return }
// Only check publicly-visible items, using the result from the privacy pass. It's an option so
// the crate root can also use this function (it doesn't have a NodeId).
match id {
Some(ref id) if !cx.exported_items.contains(id) => return,
_ => ()
}

if !attrs.iter().any(|a| a.node.is_sugared_doc) {
cx.span_lint(missing_doc, sp,
format!("missing documentation for {}", desc));
}
}

fn check_missing_doc_item(cx: &mut Context, it: &ast::item) { // XXX doesn't need to be mut
fn check_missing_doc_item(cx: &Context, it: &ast::item) {
let desc = match it.node {
ast::item_fn(..) => "a function",
ast::item_mod(..) => "a module",
Expand All @@ -1078,7 +1081,7 @@ fn check_missing_doc_item(cx: &mut Context, it: &ast::item) { // XXX doesn't nee
ast::item_trait(..) => "a trait",
_ => return
};
check_missing_doc_attrs(cx, it.id, it.attrs, it.span, desc);
check_missing_doc_attrs(cx, Some(it.id), it.attrs, it.span, desc);
}

fn check_missing_doc_method(cx: &Context, m: &ast::method) {
Expand All @@ -1104,24 +1107,24 @@ fn check_missing_doc_method(cx: &Context, m: &ast::method) {
}
}
}
check_missing_doc_attrs(cx, m.id, m.attrs, m.span, "a method");
check_missing_doc_attrs(cx, Some(m.id), m.attrs, m.span, "a method");
}

fn check_missing_doc_ty_method(cx: &Context, tm: &ast::TypeMethod) {
check_missing_doc_attrs(cx, tm.id, tm.attrs, tm.span, "a type method");
check_missing_doc_attrs(cx, Some(tm.id), tm.attrs, tm.span, "a type method");
}

fn check_missing_doc_struct_field(cx: &Context, sf: &ast::struct_field) {
match sf.node.kind {
ast::named_field(_, vis) if vis != ast::private =>
check_missing_doc_attrs(cx, cx.cur_struct_def_id, sf.node.attrs,
check_missing_doc_attrs(cx, Some(cx.cur_struct_def_id), sf.node.attrs,
sf.span, "a struct field"),
_ => {}
}
}

fn check_missing_doc_variant(cx: &Context, v: &ast::variant) {
check_missing_doc_attrs(cx, v.node.id, v.node.attrs, v.span, "a variant");
check_missing_doc_attrs(cx, Some(v.node.id), v.node.attrs, v.span, "a variant");
}

/// Checks for use of items with #[deprecated], #[experimental] and
Expand Down Expand Up @@ -1372,6 +1375,9 @@ pub fn check_crate(tcx: ty::ctxt,
});

check_crate_attrs_usage(cx, crate.attrs);
// since the root module isn't visited as an item (because it isn't an item), warn for it
// here.
check_missing_doc_attrs(cx, None, crate.attrs, crate.span, "crate");

visit::walk_crate(cx, crate, ());
});
Expand Down
1 change: 1 addition & 0 deletions src/libsyntax/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ pub fn walk_mod<E:Clone, V:Visitor<E>>(visitor: &mut V, module: &_mod, env: E) {
for view_item in module.view_items.iter() {
visitor.visit_view_item(view_item, env.clone())
}

for item in module.items.iter() {
visitor.visit_item(*item, env.clone())
}
Expand Down
14 changes: 14 additions & 0 deletions src/test/compile-fail/issue-10656.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// error-pattern: missing documentation for crate

#[deny(missing_doc)];
#[crate_type="lib"];
3 changes: 3 additions & 0 deletions src/test/compile-fail/lint-missing-doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
#[feature(globs)];
#[deny(missing_doc)];

//! Some garbage docs for the crate here
#[doc="More garbage"];

struct Foo {
a: int,
priv b: int,
Expand Down