Skip to content

Commit 6512035

Browse files
author
Keegan McAllister
committed
Make the crate and its exported items available in the lint context
1 parent c306d20 commit 6512035

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

src/librustc/lint/builtin.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,9 +1238,6 @@ declare_lint!(MISSING_DOC, Allow,
12381238
"detects missing documentation for public members")
12391239

12401240
pub struct MissingDoc {
1241-
/// Set of nodes exported from this module.
1242-
exported_items: Option<ExportedItems>,
1243-
12441241
/// Stack of IDs of struct definitions.
12451242
struct_def_stack: Vec<ast::NodeId>,
12461243

@@ -1252,7 +1249,6 @@ pub struct MissingDoc {
12521249
impl MissingDoc {
12531250
pub fn new() -> MissingDoc {
12541251
MissingDoc {
1255-
exported_items: None,
12561252
struct_def_stack: vec!(),
12571253
doc_hidden_stack: vec!(false),
12581254
}
@@ -1278,9 +1274,8 @@ impl MissingDoc {
12781274
// Only check publicly-visible items, using the result from the privacy pass.
12791275
// It's an option so the crate root can also use this function (it doesn't
12801276
// have a NodeId).
1281-
let exported = self.exported_items.as_ref().expect("exported_items not set");
12821277
match id {
1283-
Some(ref id) if !exported.contains(id) => return,
1278+
Some(ref id) if !cx.exported_items.contains(id) => return,
12841279
_ => ()
12851280
}
12861281

@@ -1327,10 +1322,7 @@ impl LintPass for MissingDoc {
13271322
assert!(popped == id);
13281323
}
13291324

1330-
fn check_crate(&mut self, cx: &Context, exported: &ExportedItems, krate: &ast::Crate) {
1331-
// FIXME: clone to avoid lifetime trickiness
1332-
self.exported_items = Some(exported.clone());
1333-
1325+
fn check_crate(&mut self, cx: &Context, _: &ExportedItems, krate: &ast::Crate) {
13341326
self.check_missing_doc_attrs(cx, None, krate.attrs.as_slice(),
13351327
krate.span, "crate");
13361328
}

src/librustc/lint/context.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,12 @@ pub struct Context<'a> {
170170
/// Type context we're checking in.
171171
pub tcx: &'a ty::ctxt,
172172

173+
/// The crate being checked.
174+
pub krate: &'a ast::Crate,
175+
176+
/// Items exported from the crate being checked.
177+
pub exported_items: &'a ExportedItems,
178+
173179
/// The store of registered lints.
174180
lints: LintStore,
175181

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

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

283291
Context {
284-
lints: lint_store,
285292
tcx: tcx,
293+
krate: krate,
294+
exported_items: exported_items,
295+
lints: lint_store,
286296
level_stack: vec!(),
287297
node_levels: RefCell::new(HashMap::new()),
288298
}
@@ -619,7 +629,7 @@ impl LintPass for GatherNodeLevels {
619629
pub fn check_crate(tcx: &ty::ctxt,
620630
exported_items: &ExportedItems,
621631
krate: &ast::Crate) {
622-
let mut cx = Context::new(tcx);
632+
let mut cx = Context::new(tcx, krate, exported_items);
623633

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

0 commit comments

Comments
 (0)