Skip to content

Commit

Permalink
Make the crate and its exported items available in the lint context
Browse files Browse the repository at this point in the history
  • Loading branch information
Keegan McAllister committed Jun 24, 2014
1 parent a813a37 commit 6fede93
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
12 changes: 2 additions & 10 deletions src/librustc/lint/builtin.rs
Expand Up @@ -1238,9 +1238,6 @@ declare_lint!(MISSING_DOC, Allow,
"detects missing documentation for public members")

pub struct MissingDoc {
/// Set of nodes exported from this module.
exported_items: Option<ExportedItems>,

/// Stack of IDs of struct definitions.
struct_def_stack: Vec<ast::NodeId>,

Expand All @@ -1252,7 +1249,6 @@ pub struct MissingDoc {
impl MissingDoc {
pub fn new() -> MissingDoc {
MissingDoc {
exported_items: None,
struct_def_stack: vec!(),
doc_hidden_stack: vec!(false),
}
Expand All @@ -1278,9 +1274,8 @@ impl MissingDoc {
// 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).
let exported = self.exported_items.as_ref().expect("exported_items not set");
match id {
Some(ref id) if !exported.contains(id) => return,
Some(ref id) if !cx.exported_items.contains(id) => return,
_ => ()
}

Expand Down Expand Up @@ -1327,10 +1322,7 @@ impl LintPass for MissingDoc {
assert!(popped == id);
}

fn check_crate(&mut self, cx: &Context, exported: &ExportedItems, krate: &ast::Crate) {
// FIXME: clone to avoid lifetime trickiness
self.exported_items = Some(exported.clone());

fn check_crate(&mut self, cx: &Context, _: &ExportedItems, krate: &ast::Crate) {
self.check_missing_doc_attrs(cx, None, krate.attrs.as_slice(),
krate.span, "crate");
}
Expand Down
16 changes: 13 additions & 3 deletions src/librustc/lint/context.rs
Expand Up @@ -170,6 +170,12 @@ pub struct Context<'a> {
/// Type context we're checking in.
pub tcx: &'a ty::ctxt,

/// The crate being checked.
pub krate: &'a ast::Crate,

/// Items exported from the crate being checked.
pub exported_items: &'a ExportedItems,

/// The store of registered lints.
lints: LintStore,

Expand Down Expand Up @@ -275,14 +281,18 @@ pub fn raw_emit_lint(sess: &Session, lint: &'static Lint,
}

impl<'a> Context<'a> {
fn new(tcx: &'a ty::ctxt) -> Context<'a> {
fn new(tcx: &'a ty::ctxt,
krate: &'a ast::Crate,
exported_items: &'a ExportedItems) -> Context<'a> {
// We want to own the lint store, so move it out of the session.
let lint_store = mem::replace(&mut *tcx.sess.lint_store.borrow_mut(),
LintStore::new());

Context {
lints: lint_store,
tcx: tcx,
krate: krate,
exported_items: exported_items,
lints: lint_store,
level_stack: vec!(),
node_levels: RefCell::new(HashMap::new()),
}
Expand Down Expand Up @@ -619,7 +629,7 @@ impl LintPass for GatherNodeLevels {
pub fn check_crate(tcx: &ty::ctxt,
krate: &ast::Crate,
exported_items: &ExportedItems) {
let mut cx = Context::new(tcx);
let mut cx = Context::new(tcx, krate, exported_items);

// Visit the whole crate.
cx.with_lint_attrs(krate.attrs.as_slice(), |cx| {
Expand Down

0 comments on commit 6fede93

Please sign in to comment.