Skip to content

Commit 33ded3e

Browse files
committed
rustdoc: Deliberately load extern crates before processing docs
In order that we can successfully later resolve paths in crates which weren't loaded as a result of merely parsing the crate we're documenting, we force the resolution of the path to each crate before cloning the resolver to use later. Closes #66159 Signed-off-by: Daniel Silverstone <[email protected]>
1 parent 2c33568 commit 33ded3e

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

src/librustdoc/core.rs

+24-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use rustc_lint;
22
use rustc::session::{self, config};
3+
use rustc::hir::def::Namespace::TypeNS;
34
use rustc::hir::def_id::{DefId, DefIndex, CrateNum, LOCAL_CRATE};
45
use rustc::hir::HirId;
56
use rustc::middle::cstore::CrateStore;
@@ -13,11 +14,13 @@ use rustc_interface::interface;
1314
use rustc_driver::abort_on_err;
1415
use rustc_resolve as resolve;
1516

17+
use syntax::ast::CRATE_NODE_ID;
1618
use syntax::source_map;
1719
use syntax::attr;
1820
use syntax::feature_gate::UnstableFeatures;
1921
use syntax::json::JsonEmitter;
2022
use syntax::symbol::sym;
23+
use syntax_pos::DUMMY_SP;
2124
use errors;
2225
use errors::emitter::{Emitter, EmitterWriter};
2326

@@ -246,6 +249,8 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
246249
..
247250
} = options;
248251

252+
let extern_names: Vec<String> = externs.iter().map(|(s,_)| s).cloned().collect();
253+
249254
// Add the rustdoc cfg into the doc build.
250255
cfgs.push("rustdoc".to_string());
251256

@@ -343,7 +348,25 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
343348
// We need to hold on to the complete resolver, so we cause everything to be
344349
// cloned for the analysis passes to use. Suboptimal, but necessary in the
345350
// current architecture.
346-
let resolver = abort_on_err(compiler.expansion(), sess).peek().1.borrow().clone();
351+
let resolver = {
352+
let parts = abort_on_err(compiler.expansion(), sess).peek();
353+
let resolver = parts.1.borrow();
354+
355+
// Before we actually clone it, let's force all the extern'd crates to
356+
// actually be loaded, just in case they're only referred to inside
357+
// intra-doc-links
358+
resolver.borrow_mut().access(|resolver| {
359+
for extern_name in &extern_names {
360+
resolver.resolve_str_path_error(DUMMY_SP, extern_name, TypeNS, CRATE_NODE_ID)
361+
.unwrap_or_else(
362+
|()| panic!("Unable to resolve external crate {}", extern_name)
363+
);
364+
}
365+
});
366+
367+
// Now we're good to clone the resolver because everything should be loaded
368+
resolver.clone()
369+
};
347370

348371
if sess.has_errors() {
349372
sess.fatal("Compilation failed, aborting rustdoc");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/// This will be referred to by the test docstring
2+
pub struct Something;

src/test/rustdoc/issue-66159.rs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// aux-build:issue-66159-1.rs
2+
// extern-private:issue_66159_1
3+
4+
// The issue was an ICE which meant that we never actually generated the docs
5+
// so if we have generated the docs, we're okay.
6+
// Since we don't generate the docs for the auxilliary files, we can't actually
7+
// verify that the struct is linked correctly.
8+
9+
// @has issue_66159/index.html
10+
//! [issue_66159_1::Something]

0 commit comments

Comments
 (0)