Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ICE when documentation includes intra-doc-link #66211

Merged
merged 2 commits into from
Nov 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/librustdoc/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,10 +608,12 @@ fn parse_extern_html_roots(
/// Extracts `--extern CRATE=PATH` arguments from `matches` and
/// returns a map mapping crate names to their paths or else an
/// error message.
/// Also handles `--extern-private` which for the purposes of rustdoc
/// we can treat as `--extern`
// FIXME(eddyb) This shouldn't be duplicated with `rustc::session`.
fn parse_externs(matches: &getopts::Matches) -> Result<Externs, String> {
let mut externs: BTreeMap<_, ExternEntry> = BTreeMap::new();
for arg in &matches.opt_strs("extern") {
for arg in matches.opt_strs("extern").iter().chain(matches.opt_strs("extern-private").iter()) {
let mut parts = arg.splitn(2, '=');
let name = parts.next().ok_or("--extern value must not be empty".to_string())?;
let location = parts.next().map(|s| s.to_string());
Expand Down
25 changes: 24 additions & 1 deletion src/librustdoc/core.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use rustc_lint;
use rustc::session::{self, config};
use rustc::hir::def::Namespace::TypeNS;
use rustc::hir::def_id::{DefId, DefIndex, CrateNum, LOCAL_CRATE};
use rustc::hir::HirId;
use rustc::middle::cstore::CrateStore;
Expand All @@ -13,11 +14,13 @@ use rustc_interface::interface;
use rustc_driver::abort_on_err;
use rustc_resolve as resolve;

use syntax::ast::CRATE_NODE_ID;
use syntax::source_map;
use syntax::attr;
use syntax::feature_gate::UnstableFeatures;
use syntax::json::JsonEmitter;
use syntax::symbol::sym;
use syntax_pos::DUMMY_SP;
use errors;
use errors::emitter::{Emitter, EmitterWriter};

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

let extern_names: Vec<String> = externs.iter().map(|(s,_)| s).cloned().collect();

// Add the rustdoc cfg into the doc build.
cfgs.push("rustdoc".to_string());

Expand Down Expand Up @@ -343,7 +348,25 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
// We need to hold on to the complete resolver, so we cause everything to be
// cloned for the analysis passes to use. Suboptimal, but necessary in the
// current architecture.
let resolver = abort_on_err(compiler.expansion(), sess).peek().1.borrow().clone();
let resolver = {
let parts = abort_on_err(compiler.expansion(), sess).peek();
let resolver = parts.1.borrow();

// Before we actually clone it, let's force all the extern'd crates to
// actually be loaded, just in case they're only referred to inside
// intra-doc-links
resolver.borrow_mut().access(|resolver| {
for extern_name in &extern_names {
resolver.resolve_str_path_error(DUMMY_SP, extern_name, TypeNS, CRATE_NODE_ID)
.unwrap_or_else(
|()| panic!("Unable to resolve external crate {}", extern_name)
);
}
});

// Now we're good to clone the resolver because everything should be loaded
resolver.clone()
};

if sess.has_errors() {
sess.fatal("Compilation failed, aborting rustdoc");
Expand Down
4 changes: 4 additions & 0 deletions src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ fn opts() -> Vec<RustcOptGroup> {
stable("extern", |o| {
o.optmulti("", "extern", "pass an --extern to rustc", "NAME=PATH")
}),
stable("extern-private", |o| {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be stable, it's not even stable in rustc: #66655

o.optmulti("", "extern-private",
"pass an --extern to rustc (compatibility only)", "NAME=PATH")
}),
unstable("extern-html-root-url", |o| {
o.optmulti("", "extern-html-root-url",
"base URL to use for dependencies", "NAME=URL")
Expand Down
2 changes: 2 additions & 0 deletions src/test/rustdoc/auxiliary/issue-66159-1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/// This will be referred to by the test docstring
pub struct Something;
10 changes: 10 additions & 0 deletions src/test/rustdoc/issue-66159.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// aux-build:issue-66159-1.rs
// extern-private:issue_66159_1

// The issue was an ICE which meant that we never actually generated the docs
// so if we have generated the docs, we're okay.
// Since we don't generate the docs for the auxilliary files, we can't actually
// verify that the struct is linked correctly.

// @has issue_66159/index.html
//! [issue_66159_1::Something]