Make correct resolver available in rustdoc
This commit is contained in:
@@ -127,7 +127,7 @@ pub struct Crate {
|
|||||||
pub masked_crates: FxHashSet<CrateNum>,
|
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 {
|
fn clean(&self, cx: &DocContext) -> Crate {
|
||||||
use ::visit_lib::LibEmbargoVisitor;
|
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
|
// but it can't because that would break object safety. This can still be
|
||||||
// fixed.
|
// fixed.
|
||||||
let components = link.split("::").skip(1).collect::<Vec<_>>();
|
let components = link.split("::").skip(1).collect::<Vec<_>>();
|
||||||
println!("{:?}", components);
|
|
||||||
cx.resolver.borrow_mut().std_path(DUMMY_SP, None, &components, false)
|
cx.resolver.borrow_mut().std_path(DUMMY_SP, None, &components, false)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -44,9 +44,9 @@ pub use rustc::session::search_paths::SearchPaths;
|
|||||||
|
|
||||||
pub type ExternalPaths = FxHashMap<DefId, (Vec<String>, clean::TypeKind)>;
|
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 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>,
|
pub populated_all_crate_impls: Cell<bool>,
|
||||||
// Note that external items for which `doc(hidden)` applies to are shown as
|
// 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
|
// 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 name = ::rustc_trans_utils::link::find_crate_name(Some(&sess), &krate.attrs, &input);
|
||||||
|
|
||||||
let driver::ExpansionResult {
|
let mut crate_loader = CrateLoader::new(&sess, &cstore, &name);
|
||||||
expanded_crate,
|
|
||||||
defs,
|
let resolver_arenas = resolve::Resolver::arenas();
|
||||||
analysis,
|
let result = driver::phase_2_configure_and_expand_inner(&sess,
|
||||||
resolutions,
|
&cstore,
|
||||||
mut hir_forest
|
krate,
|
||||||
} = {
|
None,
|
||||||
let result = driver::phase_2_configure_and_expand(&sess,
|
&name,
|
||||||
&cstore,
|
None,
|
||||||
krate,
|
resolve::MakeGlobMap::No,
|
||||||
None,
|
&resolver_arenas,
|
||||||
&name,
|
&mut crate_loader,
|
||||||
None,
|
|_| Ok(()));
|
||||||
resolve::MakeGlobMap::No,
|
let driver::InnerExpansionResult {
|
||||||
|_| Ok(()));
|
mut hir_forest,
|
||||||
abort_on_err(result, &sess)
|
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 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 hir_map = hir_map::map_crate(&sess, &*cstore, &mut hir_forest, &defs);
|
||||||
let output_filenames = driver::build_output_filenames(&input,
|
let output_filenames = driver::build_output_filenames(&input,
|
||||||
&None,
|
&None,
|
||||||
@@ -190,6 +206,8 @@ pub fn run_core(search_paths: SearchPaths,
|
|||||||
&[],
|
&[],
|
||||||
&sess);
|
&sess);
|
||||||
|
|
||||||
|
let resolver = RefCell::new(resolver);
|
||||||
|
|
||||||
abort_on_err(driver::phase_3_run_analysis_passes(&*trans,
|
abort_on_err(driver::phase_3_run_analysis_passes(&*trans,
|
||||||
control,
|
control,
|
||||||
&sess,
|
&sess,
|
||||||
@@ -215,20 +233,9 @@ pub fn run_core(search_paths: SearchPaths,
|
|||||||
.collect()
|
.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 {
|
let ctxt = DocContext {
|
||||||
tcx,
|
tcx,
|
||||||
resolver: RefCell::new(resolver),
|
resolver: &resolver,
|
||||||
populated_all_crate_impls: Cell::new(false),
|
populated_all_crate_impls: Cell::new(false),
|
||||||
access_levels: RefCell::new(access_levels),
|
access_levels: RefCell::new(access_levels),
|
||||||
external_traits: Default::default(),
|
external_traits: Default::default(),
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
|
html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
|
||||||
html_root_url = "https://doc.rust-lang.org/nightly/",
|
html_root_url = "https://doc.rust-lang.org/nightly/",
|
||||||
html_playground_url = "https://play.rust-lang.org/")]
|
html_playground_url = "https://play.rust-lang.org/")]
|
||||||
#![deny(warnings)]
|
|
||||||
|
|
||||||
#![feature(ascii_ctype)]
|
#![feature(ascii_ctype)]
|
||||||
#![feature(rustc_private)]
|
#![feature(rustc_private)]
|
||||||
|
|||||||
@@ -40,11 +40,11 @@ use doctree::*;
|
|||||||
// also, is there some reason that this doesn't use the 'visit'
|
// also, is there some reason that this doesn't use the 'visit'
|
||||||
// framework from syntax?
|
// framework from syntax?
|
||||||
|
|
||||||
pub struct RustdocVisitor<'a, 'tcx: 'a, 'rcx: 'a> {
|
pub struct RustdocVisitor<'a, 'b: 'a, 'tcx: 'b, 'rcx: 'b> {
|
||||||
cstore: &'tcx CrateStore,
|
cstore: &'a CrateStore,
|
||||||
pub module: Module,
|
pub module: Module,
|
||||||
pub attrs: hir::HirVec<ast::Attribute>,
|
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>,
|
view_item_stack: FxHashSet<ast::NodeId>,
|
||||||
inlining: bool,
|
inlining: bool,
|
||||||
/// Is the current module and all of its parents public?
|
/// 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>,
|
reexported_macros: FxHashSet<DefId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
|
impl<'a, 'b, 'tcx, 'rcx> RustdocVisitor<'a, 'b, 'tcx, 'rcx> {
|
||||||
pub fn new(cstore: &'tcx CrateStore,
|
pub fn new(cstore: &'a CrateStore,
|
||||||
cx: &'a core::DocContext<'a, 'tcx, 'rcx>) -> RustdocVisitor<'a, 'tcx, 'rcx> {
|
cx: &'a core::DocContext<'b, 'tcx, 'rcx>) -> RustdocVisitor<'a, 'b, 'tcx, 'rcx> {
|
||||||
// If the root is re-exported, terminate all recursion.
|
// If the root is re-exported, terminate all recursion.
|
||||||
let mut stack = FxHashSet();
|
let mut stack = FxHashSet();
|
||||||
stack.insert(ast::CRATE_NODE_ID);
|
stack.insert(ast::CRATE_NODE_ID);
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ use clean::{AttributesExt, NestedAttributesExt};
|
|||||||
|
|
||||||
/// Similar to `librustc_privacy::EmbargoVisitor`, but also takes
|
/// Similar to `librustc_privacy::EmbargoVisitor`, but also takes
|
||||||
/// specific rustdoc annotations into account (i.e. `doc(hidden)`)
|
/// 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>,
|
cx: &'a ::core::DocContext<'b, 'tcx, 'rcx>,
|
||||||
// Accessibility levels for reachable nodes
|
// Accessibility levels for reachable nodes
|
||||||
access_levels: RefMut<'a, AccessLevels<DefId>>,
|
access_levels: RefMut<'a, AccessLevels<DefId>>,
|
||||||
|
|||||||
Reference in New Issue
Block a user