Make correct resolver available in rustdoc

This commit is contained in:
Manish Goregaokar 2017-12-25 14:34:56 +05:30
parent fe0c10019d
commit dae2e22e81
5 changed files with 48 additions and 42 deletions

View File

@ -127,7 +127,7 @@ pub struct Crate {
pub masked_crates: FxHashSet<CrateNum>,
}
impl<'a, 'tcx, 'rcx> Clean<Crate> for visit_ast::RustdocVisitor<'a, 'tcx, 'rcx> {
impl<'a, 'b, 'tcx, 'rcx> Clean<Crate> for visit_ast::RustdocVisitor<'a, 'b, 'tcx, 'rcx> {
fn clean(&self, cx: &DocContext) -> Crate {
use ::visit_lib::LibEmbargoVisitor;
@ -821,7 +821,6 @@ impl Clean<Attributes> for [ast::Attribute] {
// but it can't because that would break object safety. This can still be
// fixed.
let components = link.split("::").skip(1).collect::<Vec<_>>();
println!("{:?}", components);
cx.resolver.borrow_mut().std_path(DUMMY_SP, None, &components, false)
};

View File

@ -44,9 +44,9 @@ pub use rustc::session::search_paths::SearchPaths;
pub type ExternalPaths = FxHashMap<DefId, (Vec<String>, clean::TypeKind)>;
pub struct DocContext<'a, 'tcx: 'a, 'rcx> {
pub struct DocContext<'a, 'tcx: 'a, 'rcx: 'a> {
pub tcx: TyCtxt<'a, 'tcx, 'tcx>,
pub resolver: RefCell<resolve::Resolver<'rcx>>,
pub resolver: &'a RefCell<resolve::Resolver<'rcx>>,
pub populated_all_crate_impls: Cell<bool>,
// Note that external items for which `doc(hidden)` applies to are shown as
// non-reachable while local items aren't. This is because we're reusing
@ -162,27 +162,43 @@ pub fn run_core(search_paths: SearchPaths,
let name = ::rustc_trans_utils::link::find_crate_name(Some(&sess), &krate.attrs, &input);
let driver::ExpansionResult {
expanded_crate,
defs,
analysis,
resolutions,
mut hir_forest
} = {
let result = driver::phase_2_configure_and_expand(&sess,
&cstore,
krate,
None,
&name,
None,
resolve::MakeGlobMap::No,
|_| Ok(()));
abort_on_err(result, &sess)
let mut crate_loader = CrateLoader::new(&sess, &cstore, &name);
let resolver_arenas = resolve::Resolver::arenas();
let result = driver::phase_2_configure_and_expand_inner(&sess,
&cstore,
krate,
None,
&name,
None,
resolve::MakeGlobMap::No,
&resolver_arenas,
&mut crate_loader,
|_| Ok(()));
let driver::InnerExpansionResult {
mut hir_forest,
resolver,
..
} = abort_on_err(result, &sess);
// We need to hold on to the complete resolver, so we clone everything
// for the analysis passes to use. Suboptimal, but necessary in the
// current architecture.
let defs = resolver.definitions.clone();
let resolutions = ty::Resolutions {
freevars: resolver.freevars.clone(),
export_map: resolver.export_map.clone(),
trait_map: resolver.trait_map.clone(),
maybe_unused_trait_imports: resolver.maybe_unused_trait_imports.clone(),
maybe_unused_extern_crates: resolver.maybe_unused_extern_crates.clone(),
};
let analysis = ty::CrateAnalysis {
access_levels: Rc::new(AccessLevels::default()),
name: name.to_string(),
glob_map: if resolver.make_glob_map { Some(resolver.glob_map.clone()) } else { None },
};
let arenas = AllArenas::new();
let mut crate_loader = CrateLoader::new(&sess, &cstore, &name);
let resolver_arenas = resolve::Resolver::arenas();
let hir_map = hir_map::map_crate(&sess, &*cstore, &mut hir_forest, &defs);
let output_filenames = driver::build_output_filenames(&input,
&None,
@ -190,6 +206,8 @@ pub fn run_core(search_paths: SearchPaths,
&[],
&sess);
let resolver = RefCell::new(resolver);
abort_on_err(driver::phase_3_run_analysis_passes(&*trans,
control,
&sess,
@ -215,20 +233,9 @@ pub fn run_core(search_paths: SearchPaths,
.collect()
};
// Set up a Resolver so that the doc cleaning can look up paths in the docs
let mut resolver = resolve::Resolver::new(&sess,
&*cstore,
&expanded_crate,
&name,
resolve::MakeGlobMap::No,
&mut crate_loader,
&resolver_arenas);
resolver.resolve_imports();
resolver.resolve_crate(&expanded_crate);
let ctxt = DocContext {
tcx,
resolver: RefCell::new(resolver),
resolver: &resolver,
populated_all_crate_impls: Cell::new(false),
access_levels: RefCell::new(access_levels),
external_traits: Default::default(),

View File

@ -12,7 +12,7 @@
html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
html_root_url = "https://doc.rust-lang.org/nightly/",
html_playground_url = "https://play.rust-lang.org/")]
#![deny(warnings)]
#![feature(ascii_ctype)]
#![feature(rustc_private)]

View File

@ -40,11 +40,11 @@ use doctree::*;
// also, is there some reason that this doesn't use the 'visit'
// framework from syntax?
pub struct RustdocVisitor<'a, 'tcx: 'a, 'rcx: 'a> {
cstore: &'tcx CrateStore,
pub struct RustdocVisitor<'a, 'b: 'a, 'tcx: 'b, 'rcx: 'b> {
cstore: &'a CrateStore,
pub module: Module,
pub attrs: hir::HirVec<ast::Attribute>,
pub cx: &'a core::DocContext<'a, 'tcx, 'rcx>,
pub cx: &'a core::DocContext<'b, 'tcx, 'rcx>,
view_item_stack: FxHashSet<ast::NodeId>,
inlining: bool,
/// Is the current module and all of its parents public?
@ -52,9 +52,9 @@ pub struct RustdocVisitor<'a, 'tcx: 'a, 'rcx: 'a> {
reexported_macros: FxHashSet<DefId>,
}
impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
pub fn new(cstore: &'tcx CrateStore,
cx: &'a core::DocContext<'a, 'tcx, 'rcx>) -> RustdocVisitor<'a, 'tcx, 'rcx> {
impl<'a, 'b, 'tcx, 'rcx> RustdocVisitor<'a, 'b, 'tcx, 'rcx> {
pub fn new(cstore: &'a CrateStore,
cx: &'a core::DocContext<'b, 'tcx, 'rcx>) -> RustdocVisitor<'a, 'b, 'tcx, 'rcx> {
// If the root is re-exported, terminate all recursion.
let mut stack = FxHashSet();
stack.insert(ast::CRATE_NODE_ID);

View File

@ -22,7 +22,7 @@ use clean::{AttributesExt, NestedAttributesExt};
/// Similar to `librustc_privacy::EmbargoVisitor`, but also takes
/// specific rustdoc annotations into account (i.e. `doc(hidden)`)
pub struct LibEmbargoVisitor<'a, 'b: 'a, 'tcx: 'b, 'rcx: 'a> {
pub struct LibEmbargoVisitor<'a, 'b: 'a, 'tcx: 'b, 'rcx: 'b> {
cx: &'a ::core::DocContext<'b, 'tcx, 'rcx>,
// Accessibility levels for reachable nodes
access_levels: RefMut<'a, AccessLevels<DefId>>,