Skip to content

Commit c7d5832

Browse files
committed
Auto merge of #30149 - mitaa:fqn, r=alexcrichton
Fixes #30109
2 parents 372e82c + af1ad41 commit c7d5832

File tree

7 files changed

+84
-10
lines changed

7 files changed

+84
-10
lines changed

src/compiletest/header.rs

+12
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ pub struct TestProps {
3434
pub exec_env: Vec<(String,String)> ,
3535
// Lines to check if they appear in the expected debugger output
3636
pub check_lines: Vec<String> ,
37+
// Build documentation for all specified aux-builds as well
38+
pub build_aux_docs: bool,
3739
// Flag to force a crate to be built with the host architecture
3840
pub force_host: bool,
3941
// Check stdout for error-pattern output as well as stderr
@@ -59,6 +61,7 @@ pub fn load_props(testfile: &Path) -> TestProps {
5961
let mut run_flags = None;
6062
let mut pp_exact = None;
6163
let mut check_lines = Vec::new();
64+
let mut build_aux_docs = false;
6265
let mut force_host = false;
6366
let mut check_stdout = false;
6467
let mut no_prefer_dynamic = false;
@@ -83,6 +86,10 @@ pub fn load_props(testfile: &Path) -> TestProps {
8386
pp_exact = parse_pp_exact(ln, testfile);
8487
}
8588

89+
if !build_aux_docs {
90+
build_aux_docs = parse_build_aux_docs(ln);
91+
}
92+
8693
if !force_host {
8794
force_host = parse_force_host(ln);
8895
}
@@ -144,6 +151,7 @@ pub fn load_props(testfile: &Path) -> TestProps {
144151
aux_builds: aux_builds,
145152
exec_env: exec_env,
146153
check_lines: check_lines,
154+
build_aux_docs: build_aux_docs,
147155
force_host: force_host,
148156
check_stdout: check_stdout,
149157
no_prefer_dynamic: no_prefer_dynamic,
@@ -284,6 +292,10 @@ fn parse_force_host(line: &str) -> bool {
284292
parse_name_directive(line, "force-host")
285293
}
286294

295+
fn parse_build_aux_docs(line: &str) -> bool {
296+
parse_name_directive(line, "build-aux-docs")
297+
}
298+
287299
fn parse_check_stdout(line: &str) -> bool {
288300
parse_name_directive(line, "check-stdout")
289301
}

src/compiletest/runtest.rs

+19-6
Original file line numberDiff line numberDiff line change
@@ -1149,11 +1149,20 @@ fn compile_test(config: &Config, props: &TestProps,
11491149
}
11501150

11511151
fn document(config: &Config, props: &TestProps,
1152-
testfile: &Path) -> (ProcRes, PathBuf) {
1152+
testfile: &Path, out_dir: &Path) -> ProcRes {
1153+
if props.build_aux_docs {
1154+
for rel_ab in &props.aux_builds {
1155+
let abs_ab = config.aux_base.join(rel_ab);
1156+
let aux_props = header::load_props(&abs_ab);
1157+
1158+
let auxres = document(config, &aux_props, &abs_ab, out_dir);
1159+
if !auxres.status.success() {
1160+
return auxres;
1161+
}
1162+
}
1163+
}
1164+
11531165
let aux_dir = aux_output_dir_name(config, testfile);
1154-
let out_dir = output_base_name(config, testfile);
1155-
let _ = fs::remove_dir_all(&out_dir);
1156-
ensure_dir(&out_dir);
11571166
let mut args = vec!["-L".to_owned(),
11581167
aux_dir.to_str().unwrap().to_owned(),
11591168
"-o".to_owned(),
@@ -1164,7 +1173,7 @@ fn document(config: &Config, props: &TestProps,
11641173
prog: config.rustdoc_path.to_str().unwrap().to_owned(),
11651174
args: args,
11661175
};
1167-
(compose_and_run_compiler(config, props, testfile, args, None), out_dir)
1176+
compose_and_run_compiler(config, props, testfile, args, None)
11681177
}
11691178

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

17251734
fn run_rustdoc_test(config: &Config, props: &TestProps, testfile: &Path) {
1726-
let (proc_res, out_dir) = document(config, props, testfile);
1735+
let out_dir = output_base_name(config, testfile);
1736+
let _ = fs::remove_dir_all(&out_dir);
1737+
ensure_dir(&out_dir);
1738+
1739+
let proc_res = document(config, props, testfile, &out_dir);
17271740
if !proc_res.status.success() {
17281741
fatal_proc_rec("rustdoc failed!", &proc_res);
17291742
}

src/librustc/middle/cstore.rs

+2
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ pub trait CrateStore<'tcx> : Any {
142142
fn item_type(&self, tcx: &ty::ctxt<'tcx>, def: DefId)
143143
-> ty::TypeScheme<'tcx>;
144144
fn item_path(&self, def: DefId) -> Vec<hir_map::PathElem>;
145+
fn extern_item_path(&self, def: DefId) -> Vec<hir_map::PathElem>;
145146
fn item_name(&self, def: DefId) -> ast::Name;
146147
fn item_predicates(&self, tcx: &ty::ctxt<'tcx>, def: DefId)
147148
-> ty::GenericPredicates<'tcx>;
@@ -295,6 +296,7 @@ impl<'tcx> CrateStore<'tcx> for DummyCrateStore {
295296
fn item_type(&self, tcx: &ty::ctxt<'tcx>, def: DefId)
296297
-> ty::TypeScheme<'tcx> { unimplemented!() }
297298
fn item_path(&self, def: DefId) -> Vec<hir_map::PathElem> { unimplemented!() }
299+
fn extern_item_path(&self, def: DefId) -> Vec<hir_map::PathElem> { unimplemented!() }
298300
fn item_name(&self, def: DefId) -> ast::Name { unimplemented!() }
299301
fn item_predicates(&self, tcx: &ty::ctxt<'tcx>, def: DefId)
300302
-> ty::GenericPredicates<'tcx> { unimplemented!() }

src/librustc_metadata/csearch.rs

+15-3
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@ use middle::lang_items;
2121
use middle::ty::{self, Ty};
2222
use middle::def_id::{DefId, DefIndex};
2323

24-
use rustc::front::map as ast_map;
24+
use rustc::front::map as hir_map;
2525
use rustc::util::nodemap::{FnvHashMap, NodeMap, NodeSet};
2626

2727
use std::cell::RefCell;
2828
use std::rc::Rc;
2929
use std::path::PathBuf;
3030
use syntax::ast;
3131
use syntax::attr;
32+
use syntax::parse::token;
3233
use rustc_back::svh::Svh;
3334
use rustc_back::target::Target;
3435
use rustc_front::hir;
@@ -115,7 +116,7 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
115116
decoder::get_method_arg_names(&cdata, did.index)
116117
}
117118

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

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

131+
fn extern_item_path(&self, def: DefId) -> Vec<hir_map::PathElem> {
132+
let cdata = self.get_crate_data(def.krate);
133+
let path = decoder::get_item_path(&*cdata, def.index);
134+
135+
let mut r = Vec::with_capacity(path.len() + 1);
136+
let crate_name = hir_map::PathMod(token::intern(&cdata.name));
137+
r.push(crate_name);
138+
r.push_all(&path);
139+
r
140+
}
141+
130142
fn item_name(&self, def: DefId) -> ast::Name {
131143
let cdata = self.get_crate_data(def.krate);
132144
decoder::get_item_name(&self.intr, &cdata, def.index)
@@ -350,7 +362,7 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
350362
decoder::get_reachable_ids(&*cdata)
351363
}
352364

353-
fn def_path(&self, def: DefId) -> ast_map::DefPath
365+
fn def_path(&self, def: DefId) -> hir_map::DefPath
354366
{
355367
let cdata = self.get_crate_data(def.krate);
356368
let path = decoder::def_path(&*cdata, def.index);

src/librustdoc/clean/inline.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ pub fn load_attrs(cx: &DocContext, tcx: &ty::ctxt,
138138
pub fn record_extern_fqn(cx: &DocContext, did: DefId, kind: clean::TypeKind) {
139139
match cx.tcx_opt() {
140140
Some(tcx) => {
141-
let fqn = tcx.sess.cstore.item_path(did);
141+
let fqn = tcx.sess.cstore.extern_item_path(did);
142142
let fqn = fqn.into_iter().map(|i| i.to_string()).collect();
143143
cx.external_paths.borrow_mut().as_mut().unwrap().insert(did, (fqn, kind));
144144
}

src/test/auxiliary/issue-30109-1.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
pub struct Bar;

src/test/rustdoc/issue-30109.rs

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// build-aux-docs
12+
// aux-build:issue-30109-1.rs
13+
// ignore-cross-compile
14+
15+
pub mod quux {
16+
extern crate issue_30109_1 as bar;
17+
use self::bar::Bar;
18+
19+
pub trait Foo {}
20+
21+
// @has issue_30109/quux/trait.Foo.html \
22+
// '//a/@href' '../issue_30109_1/struct.Bar.html'
23+
impl Foo for Bar {}
24+
}

0 commit comments

Comments
 (0)