Use the extern item-path for documentation links

The local item-path includes the local crates path to the extern crate
declaration which breaks cross-crate rustdoc links if the extern crate
is not linked into the crate root or renamed via `extern foo as bar`.
This commit is contained in:
mitaa 2015-12-03 23:11:19 +01:00
parent 14f504c5b7
commit af1ad419e1
5 changed files with 53 additions and 4 deletions

View File

@ -142,6 +142,7 @@ fn closure_ty(&self, tcx: &ty::ctxt<'tcx>, def_id: DefId)
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>;
@ -295,6 +296,7 @@ fn repr_attrs(&self, def: DefId) -> Vec<attr::ReprAttr> { unimplemented!() }
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!() }

View File

@ -21,7 +21,7 @@
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;
@ -29,6 +29,7 @@
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;
@ -115,7 +116,7 @@ fn method_arg_names(&self, did: DefId) -> Vec<String>
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);
@ -127,6 +128,17 @@ fn item_path(&self, def: DefId) -> Vec<ast_map::PathElem> {
})
}
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)
@ -350,7 +362,7 @@ fn reachable_ids(&self, cnum: ast::CrateNum) -> Vec<DefId>
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);

View File

@ -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));
}

View File

@ -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;

View File

@ -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 {}
}