mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-29 20:46:07 +03:00
Make the crate and its exported items available in the lint context
This commit is contained in:
@@ -1238,9 +1238,6 @@ fn check_expr(&mut self, cx: &Context, e: &ast::Expr) {
|
||||
"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>,
|
||||
|
||||
@@ -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 @@ fn check_missing_doc_attrs(&self,
|
||||
// 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 @@ fn check_struct_def_post(&mut self, _: &Context,
|
||||
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");
|
||||
}
|
||||
|
||||
@@ -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 @@ fn check_item(&mut self, cx: &Context, it: &ast::Item) {
|
||||
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| {
|
||||
|
||||
Reference in New Issue
Block a user