add a rustc_resolve::Resolver to DocContext
This commit is contained in:
parent
d9c1a17eec
commit
76f831647a
4 changed files with 33 additions and 12 deletions
|
@ -124,7 +124,7 @@ pub struct Crate {
|
|||
pub masked_crates: FxHashSet<CrateNum>,
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> Clean<Crate> for visit_ast::RustdocVisitor<'a, 'tcx> {
|
||||
impl<'a, 'tcx, 'rcx> Clean<Crate> for visit_ast::RustdocVisitor<'a, 'tcx, 'rcx> {
|
||||
fn clean(&self, cx: &DocContext) -> Crate {
|
||||
use ::visit_lib::LibEmbargoVisitor;
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ use rustc::lint;
|
|||
use rustc::util::nodemap::FxHashMap;
|
||||
use rustc_trans;
|
||||
use rustc_resolve as resolve;
|
||||
use rustc_metadata::creader::CrateLoader;
|
||||
use rustc_metadata::cstore::CStore;
|
||||
|
||||
use syntax::codemap;
|
||||
|
@ -43,8 +44,9 @@ pub use rustc::session::search_paths::SearchPaths;
|
|||
|
||||
pub type ExternalPaths = FxHashMap<DefId, (Vec<String>, clean::TypeKind)>;
|
||||
|
||||
pub struct DocContext<'a, 'tcx: 'a> {
|
||||
pub struct DocContext<'a, 'tcx: 'a, 'rcx> {
|
||||
pub tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
pub resolver: 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
|
||||
|
@ -67,7 +69,7 @@ pub struct DocContext<'a, 'tcx: 'a> {
|
|||
pub lt_substs: RefCell<FxHashMap<DefId, clean::Lifetime>>,
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> DocContext<'a, 'tcx> {
|
||||
impl<'a, 'tcx, 'rcx> DocContext<'a, 'tcx, 'rcx> {
|
||||
pub fn sess(&self) -> &session::Session {
|
||||
&self.tcx.sess
|
||||
}
|
||||
|
@ -160,7 +162,13 @@ pub fn run_core(search_paths: SearchPaths,
|
|||
|
||||
let name = ::rustc_trans_utils::link::find_crate_name(Some(&sess), &krate.attrs, &input);
|
||||
|
||||
let driver::ExpansionResult { defs, analysis, resolutions, mut hir_forest, .. } = {
|
||||
let driver::ExpansionResult {
|
||||
expanded_crate,
|
||||
defs,
|
||||
analysis,
|
||||
resolutions,
|
||||
mut hir_forest
|
||||
} = {
|
||||
let result = driver::phase_2_configure_and_expand(&sess,
|
||||
&cstore,
|
||||
krate,
|
||||
|
@ -173,6 +181,8 @@ pub fn run_core(search_paths: SearchPaths,
|
|||
};
|
||||
|
||||
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,
|
||||
|
@ -205,8 +215,19 @@ 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_crate(&expanded_crate);
|
||||
|
||||
let ctxt = DocContext {
|
||||
tcx,
|
||||
resolver,
|
||||
populated_all_crate_impls: Cell::new(false),
|
||||
access_levels: RefCell::new(access_levels),
|
||||
external_traits: Default::default(),
|
||||
|
|
|
@ -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> {
|
||||
pub struct RustdocVisitor<'a, 'tcx: 'a, 'rcx: 'a> {
|
||||
cstore: &'tcx CrateStore,
|
||||
pub module: Module,
|
||||
pub attrs: hir::HirVec<ast::Attribute>,
|
||||
pub cx: &'a core::DocContext<'a, 'tcx>,
|
||||
pub cx: &'a core::DocContext<'a, '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> {
|
|||
reexported_macros: FxHashSet<DefId>,
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
||||
impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
|
||||
pub fn new(cstore: &'tcx CrateStore,
|
||||
cx: &'a core::DocContext<'a, 'tcx>) -> RustdocVisitor<'a, 'tcx> {
|
||||
cx: &'a core::DocContext<'a, 'tcx, 'rcx>) -> RustdocVisitor<'a, 'tcx, 'rcx> {
|
||||
// If the root is re-exported, terminate all recursion.
|
||||
let mut stack = FxHashSet();
|
||||
stack.insert(ast::CRATE_NODE_ID);
|
||||
|
|
|
@ -22,8 +22,8 @@ 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> {
|
||||
cx: &'a ::core::DocContext<'b, 'tcx>,
|
||||
pub struct LibEmbargoVisitor<'a, 'b: 'a, 'tcx: 'b, 'rcx: 'a> {
|
||||
cx: &'a ::core::DocContext<'b, 'tcx, 'rcx>,
|
||||
// Accessibility levels for reachable nodes
|
||||
access_levels: RefMut<'a, AccessLevels<DefId>>,
|
||||
// Previous accessibility level, None means unreachable
|
||||
|
@ -32,8 +32,8 @@ pub struct LibEmbargoVisitor<'a, 'b: 'a, 'tcx: 'b> {
|
|||
visited_mods: FxHashSet<DefId>,
|
||||
}
|
||||
|
||||
impl<'a, 'b, 'tcx> LibEmbargoVisitor<'a, 'b, 'tcx> {
|
||||
pub fn new(cx: &'a ::core::DocContext<'b, 'tcx>) -> LibEmbargoVisitor<'a, 'b, 'tcx> {
|
||||
impl<'a, 'b, 'tcx, 'rcx> LibEmbargoVisitor<'a, 'b, 'tcx, 'rcx> {
|
||||
pub fn new(cx: &'a ::core::DocContext<'b, 'tcx, 'rcx>) -> LibEmbargoVisitor<'a, 'b, 'tcx, 'rcx> {
|
||||
LibEmbargoVisitor {
|
||||
cx,
|
||||
access_levels: cx.access_levels.borrow_mut(),
|
||||
|
|
Loading…
Reference in a new issue