diff options
| author | Manish Goregaokar <manishsmail@gmail.com> | 2017-12-25 14:34:56 +0530 |
|---|---|---|
| committer | Manish Goregaokar <manishsmail@gmail.com> | 2018-01-22 15:24:23 +0530 |
| commit | dae2e22e814931ea26e571c7d6e72aa1b05a871d (patch) | |
| tree | bb0c1fcbdf6547751fd5c89027d45d485ce08599 | |
| parent | fe0c10019d7ee96909cc42cc265ef999a6b5dd70 (diff) | |
| download | rust-dae2e22e814931ea26e571c7d6e72aa1b05a871d.tar.gz rust-dae2e22e814931ea26e571c7d6e72aa1b05a871d.zip | |
Make correct resolver available in rustdoc
| -rw-r--r-- | src/librustdoc/clean/mod.rs | 3 | ||||
| -rw-r--r-- | src/librustdoc/core.rs | 71 | ||||
| -rw-r--r-- | src/librustdoc/lib.rs | 2 | ||||
| -rw-r--r-- | src/librustdoc/visit_ast.rs | 12 | ||||
| -rw-r--r-- | src/librustdoc/visit_lib.rs | 2 |
5 files changed, 48 insertions, 42 deletions
diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 816b8caf23e..b890a980d43 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -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) }; diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index b849c433ec3..6fc21f0541b 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -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(), diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 01c2a5620da..5206c3667b0 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -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)] diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index 23a2208292a..d2f7da29b33 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -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); diff --git a/src/librustdoc/visit_lib.rs b/src/librustdoc/visit_lib.rs index 7da0a7bfe6e..55f3fdefd1b 100644 --- a/src/librustdoc/visit_lib.rs +++ b/src/librustdoc/visit_lib.rs @@ -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>>, |
