make missing_doc lint respect the visibility rules
Previously, the `exported_items` set created by the privacy pass was incomplete. Specifically, it did not include items that had been defined at a private path but then `pub use`d at a public path. This commit finds all crate exports during the privacy pass. Consequently, some code in the reachable pass and in rustdoc is no longer necessary. This commit then removes the separate `MissingDocLintVisitor` lint pass, opting to check missing_doc lint in the same pass as the other lint checkers using the visibility result computed by the privacy pass. Fixes #9777.
This commit is contained in:
parent
4d9b95fada
commit
1f7eb4f9aa
8 changed files with 252 additions and 243 deletions
|
|
@ -13,14 +13,13 @@ use rustc::{driver, middle};
|
|||
use rustc::middle::privacy;
|
||||
|
||||
use syntax::ast;
|
||||
use syntax::ast_util::is_local;
|
||||
use syntax::diagnostic;
|
||||
use syntax::parse;
|
||||
use syntax;
|
||||
|
||||
use std::os;
|
||||
use std::local_data;
|
||||
use std::hashmap::{HashMap,HashSet};
|
||||
use std::hashmap::{HashSet};
|
||||
|
||||
use visit_ast::RustdocVisitor;
|
||||
use clean;
|
||||
|
|
@ -34,7 +33,6 @@ pub struct DocContext {
|
|||
|
||||
pub struct CrateAnalysis {
|
||||
exported_items: privacy::ExportedItems,
|
||||
reexports: HashMap<ast::NodeId, ~[ast::NodeId]>,
|
||||
}
|
||||
|
||||
/// Parses, resolves, and typechecks the given crate
|
||||
|
|
@ -73,20 +71,12 @@ fn get_ast_and_resolve(cpath: &Path,
|
|||
let mut crate = phase_1_parse_input(sess, cfg.clone(), &input);
|
||||
crate = phase_2_configure_and_expand(sess, cfg, crate);
|
||||
let driver::driver::CrateAnalysis {
|
||||
exported_items, ty_cx, exp_map2, _
|
||||
exported_items, ty_cx, _
|
||||
} = phase_3_run_analysis_passes(sess, &crate);
|
||||
|
||||
let mut reexports = HashMap::new();
|
||||
for (&module, nodes) in exp_map2.iter() {
|
||||
reexports.insert(module, nodes.iter()
|
||||
.filter(|e| e.reexport && is_local(e.def_id))
|
||||
.map(|e| e.def_id.node)
|
||||
.to_owned_vec());
|
||||
}
|
||||
|
||||
debug!("crate: {:?}", crate);
|
||||
return (DocContext { crate: crate, tycx: ty_cx, sess: sess },
|
||||
CrateAnalysis { reexports: reexports, exported_items: exported_items });
|
||||
CrateAnalysis { exported_items: exported_items });
|
||||
}
|
||||
|
||||
pub fn run_core (libs: HashSet<Path>, path: &Path) -> (clean::Crate, CrateAnalysis) {
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ use std::local_data;
|
|||
|
||||
use syntax::ast;
|
||||
|
||||
use core;
|
||||
use clean;
|
||||
use clean::Item;
|
||||
use plugins;
|
||||
|
|
@ -59,17 +58,7 @@ pub fn strip_private(crate: clean::Crate) -> plugins::PluginResult {
|
|||
let mut retained = HashSet::new();
|
||||
let crate = Cell::new(crate);
|
||||
let exported_items = do local_data::get(super::analysiskey) |analysis| {
|
||||
let analysis = analysis.unwrap();
|
||||
let mut exported_items = analysis.exported_items.clone();
|
||||
{
|
||||
let mut finder = ExportedItemsFinder {
|
||||
exported_items: &mut exported_items,
|
||||
analysis: analysis,
|
||||
};
|
||||
let c = finder.fold_crate(crate.take());
|
||||
crate.put_back(c);
|
||||
}
|
||||
exported_items
|
||||
analysis.unwrap().exported_items.clone()
|
||||
};
|
||||
let mut crate = crate.take();
|
||||
|
||||
|
|
@ -90,32 +79,6 @@ pub fn strip_private(crate: clean::Crate) -> plugins::PluginResult {
|
|||
(crate, None)
|
||||
}
|
||||
|
||||
struct ExportedItemsFinder<'self> {
|
||||
exported_items: &'self mut HashSet<ast::NodeId>,
|
||||
analysis: &'self core::CrateAnalysis,
|
||||
}
|
||||
|
||||
impl<'self> fold::DocFolder for ExportedItemsFinder<'self> {
|
||||
fn fold_item(&mut self, i: Item) -> Option<Item> {
|
||||
match i.inner {
|
||||
clean::ModuleItem(*) => {
|
||||
if self.analysis.exported_items.contains(&i.id) {
|
||||
match self.analysis.reexports.find(&i.id) {
|
||||
Some(l) => {
|
||||
for &id in l.iter() {
|
||||
self.exported_items.insert(id);
|
||||
}
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
return self.fold_item_recur(i);
|
||||
}
|
||||
}
|
||||
|
||||
struct Stripper<'self> {
|
||||
retained: &'self mut HashSet<ast::NodeId>,
|
||||
exported_items: &'self HashSet<ast::NodeId>,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue