Skip to content

Rustdoc: Use the extern item-path for documentation links #30149

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

Merged
merged 2 commits into from
Dec 4, 2015
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
12 changes: 12 additions & 0 deletions src/compiletest/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ pub struct TestProps {
pub exec_env: Vec<(String,String)> ,
// Lines to check if they appear in the expected debugger output
pub check_lines: Vec<String> ,
// Build documentation for all specified aux-builds as well
pub build_aux_docs: bool,
// Flag to force a crate to be built with the host architecture
pub force_host: bool,
// Check stdout for error-pattern output as well as stderr
Expand All @@ -59,6 +61,7 @@ pub fn load_props(testfile: &Path) -> TestProps {
let mut run_flags = None;
let mut pp_exact = None;
let mut check_lines = Vec::new();
let mut build_aux_docs = false;
let mut force_host = false;
let mut check_stdout = false;
let mut no_prefer_dynamic = false;
Expand All @@ -83,6 +86,10 @@ pub fn load_props(testfile: &Path) -> TestProps {
pp_exact = parse_pp_exact(ln, testfile);
}

if !build_aux_docs {
build_aux_docs = parse_build_aux_docs(ln);
}

if !force_host {
force_host = parse_force_host(ln);
}
Expand Down Expand Up @@ -144,6 +151,7 @@ pub fn load_props(testfile: &Path) -> TestProps {
aux_builds: aux_builds,
exec_env: exec_env,
check_lines: check_lines,
build_aux_docs: build_aux_docs,
force_host: force_host,
check_stdout: check_stdout,
no_prefer_dynamic: no_prefer_dynamic,
Expand Down Expand Up @@ -284,6 +292,10 @@ fn parse_force_host(line: &str) -> bool {
parse_name_directive(line, "force-host")
}

fn parse_build_aux_docs(line: &str) -> bool {
parse_name_directive(line, "build-aux-docs")
}

fn parse_check_stdout(line: &str) -> bool {
parse_name_directive(line, "check-stdout")
}
Expand Down
25 changes: 19 additions & 6 deletions src/compiletest/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1149,11 +1149,20 @@ fn compile_test(config: &Config, props: &TestProps,
}

fn document(config: &Config, props: &TestProps,
testfile: &Path) -> (ProcRes, PathBuf) {
testfile: &Path, out_dir: &Path) -> ProcRes {
if props.build_aux_docs {
for rel_ab in &props.aux_builds {
let abs_ab = config.aux_base.join(rel_ab);
let aux_props = header::load_props(&abs_ab);

let auxres = document(config, &aux_props, &abs_ab, out_dir);
if !auxres.status.success() {
return auxres;
}
}
}

let aux_dir = aux_output_dir_name(config, testfile);
let out_dir = output_base_name(config, testfile);
let _ = fs::remove_dir_all(&out_dir);
ensure_dir(&out_dir);
let mut args = vec!["-L".to_owned(),
aux_dir.to_str().unwrap().to_owned(),
"-o".to_owned(),
Expand All @@ -1164,7 +1173,7 @@ fn document(config: &Config, props: &TestProps,
prog: config.rustdoc_path.to_str().unwrap().to_owned(),
args: args,
};
(compose_and_run_compiler(config, props, testfile, args, None), out_dir)
compose_and_run_compiler(config, props, testfile, args, None)
}

fn exec_compiled_test(config: &Config, props: &TestProps,
Expand Down Expand Up @@ -1723,7 +1732,11 @@ fn charset() -> &'static str {
}

fn run_rustdoc_test(config: &Config, props: &TestProps, testfile: &Path) {
let (proc_res, out_dir) = document(config, props, testfile);
let out_dir = output_base_name(config, testfile);
let _ = fs::remove_dir_all(&out_dir);
ensure_dir(&out_dir);

let proc_res = document(config, props, testfile, &out_dir);
if !proc_res.status.success() {
fatal_proc_rec("rustdoc failed!", &proc_res);
}
Expand Down
2 changes: 2 additions & 0 deletions src/librustc/middle/cstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ pub trait CrateStore<'tcx> : Any {
fn item_type(&self, tcx: &ty::ctxt<'tcx>, def: DefId)
-> ty::TypeScheme<'tcx>;
fn item_path(&self, def: DefId) -> Vec<hir_map::PathElem>;
fn extern_item_path(&self, def: DefId) -> Vec<hir_map::PathElem>;
fn item_name(&self, def: DefId) -> ast::Name;
fn item_predicates(&self, tcx: &ty::ctxt<'tcx>, def: DefId)
-> ty::GenericPredicates<'tcx>;
Expand Down Expand Up @@ -295,6 +296,7 @@ impl<'tcx> CrateStore<'tcx> for DummyCrateStore {
fn item_type(&self, tcx: &ty::ctxt<'tcx>, def: DefId)
-> ty::TypeScheme<'tcx> { unimplemented!() }
fn item_path(&self, def: DefId) -> Vec<hir_map::PathElem> { unimplemented!() }
fn extern_item_path(&self, def: DefId) -> Vec<hir_map::PathElem> { unimplemented!() }
fn item_name(&self, def: DefId) -> ast::Name { unimplemented!() }
fn item_predicates(&self, tcx: &ty::ctxt<'tcx>, def: DefId)
-> ty::GenericPredicates<'tcx> { unimplemented!() }
Expand Down
18 changes: 15 additions & 3 deletions src/librustc_metadata/csearch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ use middle::lang_items;
use middle::ty::{self, Ty};
use middle::def_id::{DefId, DefIndex};

use rustc::front::map as ast_map;
use rustc::front::map as hir_map;
use rustc::util::nodemap::{FnvHashMap, NodeMap, NodeSet};

use std::cell::RefCell;
use std::rc::Rc;
use std::path::PathBuf;
use syntax::ast;
use syntax::attr;
use syntax::parse::token;
use rustc_back::svh::Svh;
use rustc_back::target::Target;
use rustc_front::hir;
Expand Down Expand Up @@ -115,7 +116,7 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
decoder::get_method_arg_names(&cdata, did.index)
}

fn item_path(&self, def: DefId) -> Vec<ast_map::PathElem> {
fn item_path(&self, def: DefId) -> Vec<hir_map::PathElem> {
let cdata = self.get_crate_data(def.krate);
let path = decoder::get_item_path(&*cdata, def.index);

Expand All @@ -127,6 +128,17 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
})
}

fn extern_item_path(&self, def: DefId) -> Vec<hir_map::PathElem> {
let cdata = self.get_crate_data(def.krate);
let path = decoder::get_item_path(&*cdata, def.index);

let mut r = Vec::with_capacity(path.len() + 1);
let crate_name = hir_map::PathMod(token::intern(&cdata.name));
r.push(crate_name);
r.push_all(&path);
r
}

fn item_name(&self, def: DefId) -> ast::Name {
let cdata = self.get_crate_data(def.krate);
decoder::get_item_name(&self.intr, &cdata, def.index)
Expand Down Expand Up @@ -350,7 +362,7 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
decoder::get_reachable_ids(&*cdata)
}

fn def_path(&self, def: DefId) -> ast_map::DefPath
fn def_path(&self, def: DefId) -> hir_map::DefPath
{
let cdata = self.get_crate_data(def.krate);
let path = decoder::def_path(&*cdata, def.index);
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ pub fn load_attrs(cx: &DocContext, tcx: &ty::ctxt,
pub fn record_extern_fqn(cx: &DocContext, did: DefId, kind: clean::TypeKind) {
match cx.tcx_opt() {
Some(tcx) => {
let fqn = tcx.sess.cstore.item_path(did);
let fqn = tcx.sess.cstore.extern_item_path(did);
let fqn = fqn.into_iter().map(|i| i.to_string()).collect();
cx.external_paths.borrow_mut().as_mut().unwrap().insert(did, (fqn, kind));
}
Expand Down
11 changes: 11 additions & 0 deletions src/test/auxiliary/issue-30109-1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

pub struct Bar;
24 changes: 24 additions & 0 deletions src/test/rustdoc/issue-30109.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// build-aux-docs
// aux-build:issue-30109-1.rs
// ignore-cross-compile

pub mod quux {
extern crate issue_30109_1 as bar;
use self::bar::Bar;

pub trait Foo {}

// @has issue_30109/quux/trait.Foo.html \
// '//a/@href' '../issue_30109_1/struct.Bar.html'
impl Foo for Bar {}
}