From 6fede93475013a5a8bef1678dfd04fef3118836e Mon Sep 17 00:00:00 2001 From: Keegan McAllister Date: Tue, 17 Jun 2014 16:55:34 -0700 Subject: [PATCH] Make the crate and its exported items available in the lint context --- src/librustc/lint/builtin.rs | 12 ++---------- src/librustc/lint/context.rs | 16 +++++++++++++--- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index 903cb7f4f2692..ee0973c90bbfe 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -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, - /// Stack of IDs of struct definitions. struct_def_stack: Vec, @@ -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), } @@ -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, _ => () } @@ -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"); } diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index 877bf6f52a4cf..fcb2ca803320e 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -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, @@ -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()), } @@ -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| {