Rollup merge of - mitaa:rdoc-crate-links, r=alexcrichton

rustdoc: Linkify extern crates

fixes 

r? @alexcrichton
This commit is contained in:
Manish Goregaokar 2016-04-26 01:44:52 +05:30
commit edbb0d5a90
8 changed files with 79 additions and 13 deletions

View File

@ -38,7 +38,7 @@ use rustc_trans::back::link;
use rustc::middle::cstore::{self, CrateStore};
use rustc::middle::privacy::AccessLevels;
use rustc::hir::def::Def;
use rustc::hir::def_id::{DefId, DefIndex};
use rustc::hir::def_id::{DefId, DefIndex, CRATE_DEF_INDEX};
use rustc::ty::subst::{self, ParamSpace, VecPerParamSpace};
use rustc::ty;
use rustc::middle::stability;
@ -2388,7 +2388,7 @@ impl Clean<Item> for doctree::ExternCrate {
name: None,
attrs: self.attrs.clean(cx),
source: self.whence.clean(cx),
def_id: cx.map.local_def_id(0),
def_id: DefId { krate: self.cnum, index: CRATE_DEF_INDEX },
visibility: self.vis.clean(cx),
stability: None,
deprecation: None,

View File

@ -232,6 +232,7 @@ pub struct Macro {
pub struct ExternCrate {
pub name: Name,
pub cnum: ast::CrateNum,
pub path: Option<String>,
pub vis: hir::Visibility,
pub attrs: hir::HirVec<ast::Attribute>,

View File

@ -57,6 +57,11 @@ pub struct TyParamBounds<'a>(pub &'a [clean::TyParamBound]);
pub struct CommaSep<'a, T: 'a>(pub &'a [T]);
pub struct AbiSpace(pub Abi);
pub struct HRef<'a> {
pub did: DefId,
pub text: &'a str,
}
impl<'a> VisSpace<'a> {
pub fn get(self) -> &'a Option<clean::Visibility> {
let VisSpace(v) = self; v
@ -363,15 +368,7 @@ fn resolved_path(w: &mut fmt::Formatter, did: DefId, path: &clean::Path,
}
}
}
match href(did) {
Some((url, shortty, fqp)) => {
write!(w, "<a class='{}' href='{}' title='{}'>{}</a>",
shortty, url, fqp.join("::"), last.name)?;
}
_ => write!(w, "{}", last.name)?,
}
write!(w, "{}", last.params)?;
write!(w, "{}{}", HRef::new(did, &last.name), last.params)?;
Ok(())
}
@ -437,6 +434,24 @@ fn tybounds(w: &mut fmt::Formatter,
}
}
impl<'a> HRef<'a> {
pub fn new(did: DefId, text: &'a str) -> HRef<'a> {
HRef { did: did, text: text }
}
}
impl<'a> fmt::Display for HRef<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match href(self.did) {
Some((url, shortty, fqp)) => {
write!(f, "<a class='{}' href='{}' title='{}'>{}</a>",
shortty, url, fqp.join("::"), self.text)
}
_ => write!(f, "{}", self.text),
}
}
}
impl fmt::Display for clean::Type {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {

View File

@ -1739,16 +1739,19 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
match myitem.inner {
clean::ExternCrateItem(ref name, ref src) => {
use html::format::HRef;
match *src {
Some(ref src) => {
write!(w, "<tr><td><code>{}extern crate {} as {};",
VisSpace(&myitem.visibility),
src,
HRef::new(myitem.def_id, src),
name)?
}
None => {
write!(w, "<tr><td><code>{}extern crate {};",
VisSpace(&myitem.visibility), name)?
VisSpace(&myitem.visibility),
HRef::new(myitem.def_id, name))?
}
}
write!(w, "</code></td></tr>")?;

View File

@ -316,7 +316,10 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
let name = renamed.unwrap_or(item.name);
match item.node {
hir::ItemExternCrate(ref p) => {
let cstore = &self.cx.sess().cstore;
om.extern_crates.push(ExternCrate {
cnum: cstore.extern_mod_stmt_cnum(item.id)
.unwrap_or(ast::CrateNum::max_value()),
name: name,
path: p.map(|x|x.to_string()),
vis: item.vis.clone(),

View File

@ -44,6 +44,7 @@ impl<'a, 'b, 'tcx> LibEmbargoVisitor<'a, 'b, 'tcx> {
pub fn visit_lib(&mut self, cnum: ast::CrateNum) {
let did = DefId { krate: cnum, index: CRATE_DEF_INDEX };
self.update(did, Some(AccessLevel::Public));
self.visit_mod(did);
}

View File

@ -0,0 +1,20 @@
// Copyright 2016 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.
// aux-build:empty.rs
// aux-build:variant-struct.rs
// ignore-cross-compile
// @has issue_33178_1/index.html
// @!has - //a/@title empty
pub extern crate empty;
// @!has - //a/@title variant_struct
pub extern crate variant_struct as foo;

View File

@ -0,0 +1,23 @@
// Copyright 2016 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.
// aux-build:empty.rs
// aux-build:variant-struct.rs
// build-aux-docs
// ignore-cross-compile
// @has issue_33178/index.html
// @has - //a/@title empty
// @has - //a/@href ../empty/index.html
pub extern crate empty;
// @has - //a/@title variant_struct
// @has - //a/@href ../variant_struct/index.html
pub extern crate variant_struct as foo;