auto merge of #14592 : alexcrichton/rust/rustdoc-links, r=huonw

These are a few assorted fixes for some issues I found this morning (details in the commits).
This commit is contained in:
bors 2014-06-04 22:21:43 -07:00
commit 073c8f10fc
7 changed files with 122 additions and 54 deletions

View File

@ -110,7 +110,7 @@ HTML_DEPS += doc/version_info.html
doc/version_info.html: $(D)/version_info.html.template $(MKFILE_DEPS) \
$(wildcard $(D)/*.*) | doc/
@$(call E, version-info: $@)
sed -e "s/VERSION/$(CFG_RELEASE)/; s/SHORT_HASH/$(shell echo \
$(Q)sed -e "s/VERSION/$(CFG_RELEASE)/; s/SHORT_HASH/$(shell echo \
$(CFG_VER_HASH) | head -c 8)/;\
s/STAMP/$(CFG_VER_HASH)/;" $< >$@
@ -156,7 +156,9 @@ doc/footer.tex: $(D)/footer.inc | doc/
# HTML (rustdoc)
DOC_TARGETS += doc/not_found.html
doc/not_found.html: $(D)/not_found.md $(HTML_DEPS) | doc/
$(RUSTDOC) $(RUSTDOC_HTML_OPTS_NO_CSS) --markdown-css http://doc.rust-lang.org/rust.css $<
@$(call E, rustdoc: $@)
$(Q)$(RUSTDOC) $(RUSTDOC_HTML_OPTS_NO_CSS) \
--markdown-css http://doc.rust-lang.org/rust.css $<
define DEF_DOC
@ -164,7 +166,7 @@ define DEF_DOC
DOC_TARGETS += doc/$(1).html
doc/$(1).html: $$(D)/$(1).md $$(HTML_DEPS) $$(RUSTDOC_DEPS_$(1)) | doc/
@$$(call E, rustdoc: $$@)
$$(RUSTDOC) $$(RUSTDOC_HTML_OPTS) $$(RUSTDOC_FLAGS_$(1)) $$<
$$(Q)$$(RUSTDOC) $$(RUSTDOC_HTML_OPTS) $$(RUSTDOC_FLAGS_$(1)) $$<
ifneq ($(ONLY_HTML_DOCS),1)

View File

@ -61,7 +61,6 @@ li {list-style-type: none; }
* [The `time` library](time/index.html)
* [The `uuid` 128-bit universally unique identifier library](uuid/index.html)
* [The `url` library](url/index.html)
* [The `workcache` library](workcache/index.html)
* [The `log` library](log/index.html)
# Tooling

View File

@ -14,11 +14,9 @@
//! These definitions are similar to their `ct` equivalents, but differ in that
//! these can be statically allocated and are slightly optimized for the runtime
#![allow(missing_doc)]
#![doc(hidden)]
use option::Option;
#[doc(hidden)]
pub enum Piece<'a> {
String(&'a str),
// FIXME(#8259): this shouldn't require the unit-value here
@ -26,12 +24,14 @@ pub enum Piece<'a> {
Argument(Argument<'a>),
}
#[doc(hidden)]
pub struct Argument<'a> {
pub position: Position,
pub format: FormatSpec,
pub method: Option<&'a Method<'a>>
}
#[doc(hidden)]
pub struct FormatSpec {
pub fill: char,
pub align: Alignment,
@ -40,38 +40,60 @@ pub struct FormatSpec {
pub width: Count,
}
/// Possible alignments that can be requested as part of a formatting directive.
#[deriving(PartialEq)]
pub enum Alignment {
/// Indication that contents should be left-aligned.
AlignLeft,
/// Indication that contents should be right-aligned.
AlignRight,
/// No alignment was requested.
AlignUnknown,
}
#[doc(hidden)]
pub enum Count {
CountIs(uint), CountIsParam(uint), CountIsNextParam, CountImplied,
}
#[doc(hidden)]
pub enum Position {
ArgumentNext, ArgumentIs(uint)
}
/// Flags which can be passed to formatting via a directive.
///
/// These flags are discovered through the `flags` field of the `Formatter`
/// structure. The flag in that structure is a union of these flags into a
/// `uint` where each flag's discriminant is the corresponding bit.
pub enum Flag {
/// A flag which enables number formatting to always print the sign of a
/// number.
FlagSignPlus,
/// Currently not a used flag
FlagSignMinus,
/// Indicates that the "alternate formatting" for a type should be used.
///
/// The meaning of this flag is type-specific.
FlagAlternate,
/// Indicates that padding should be done with a `0` character as well as
/// being aware of the sign to be printed.
FlagSignAwareZeroPad,
}
#[doc(hidden)]
pub enum Method<'a> {
Plural(Option<uint>, &'a [PluralArm<'a>], &'a [Piece<'a>]),
Select(&'a [SelectArm<'a>], &'a [Piece<'a>]),
}
#[doc(hidden)]
pub enum PluralSelector {
Keyword(PluralKeyword),
Literal(uint),
}
#[doc(hidden)]
pub enum PluralKeyword {
Zero,
One,
@ -80,11 +102,13 @@ pub enum PluralKeyword {
Many,
}
#[doc(hidden)]
pub struct PluralArm<'a> {
pub selector: PluralSelector,
pub result: &'a [Piece<'a>],
}
#[doc(hidden)]
pub struct SelectArm<'a> {
pub selector: &'a str,
pub result: &'a [Piece<'a>],

View File

@ -129,7 +129,7 @@ pub fn record_extern_fqn(cx: &core::DocContext,
match cx.maybe_typed {
core::Typed(ref tcx) => {
let fqn = csearch::get_item_path(tcx, did);
let fqn = fqn.move_iter().map(|i| i.to_str().to_string()).collect();
let fqn = fqn.move_iter().map(|i| i.to_str()).collect();
cx.external_paths.borrow_mut().get_mut_ref().insert(did, (fqn, kind));
}
core::NotTyped(..) => {}
@ -138,10 +138,18 @@ pub fn record_extern_fqn(cx: &core::DocContext,
pub fn build_external_trait(tcx: &ty::ctxt, did: ast::DefId) -> clean::Trait {
let def = ty::lookup_trait_def(tcx, did);
let methods = ty::trait_methods(tcx, did);
let methods = ty::trait_methods(tcx, did).clean();
let provided = ty::provided_trait_methods(tcx, did);
let mut methods = methods.move_iter().map(|meth| {
if provided.iter().any(|a| a.def_id == meth.def_id) {
clean::Provided(meth)
} else {
clean::Required(meth)
}
});
clean::Trait {
generics: def.generics.clean(),
methods: methods.iter().map(|i| i.clean()).collect(),
methods: methods.collect(),
parents: Vec::new(), // FIXME: this is likely wrong
}
}
@ -207,7 +215,7 @@ fn build_impls(cx: &core::DocContext,
match tcx.inherent_impls.borrow().find(&did) {
None => {}
Some(i) => {
impls.extend(i.borrow().iter().map(|&did| { build_impl(tcx, did) }));
impls.extend(i.borrow().iter().map(|&did| { build_impl(cx, tcx, did) }));
}
}
@ -223,19 +231,20 @@ fn build_impls(cx: &core::DocContext,
csearch::each_top_level_item_of_crate(&tcx.sess.cstore,
did.krate,
|def, _, _| {
populate_impls(tcx, def, &mut impls)
populate_impls(cx, tcx, def, &mut impls)
});
fn populate_impls(tcx: &ty::ctxt,
fn populate_impls(cx: &core::DocContext,
tcx: &ty::ctxt,
def: decoder::DefLike,
impls: &mut Vec<clean::Item>) {
impls: &mut Vec<Option<clean::Item>>) {
match def {
decoder::DlImpl(did) => impls.push(build_impl(tcx, did)),
decoder::DlImpl(did) => impls.push(build_impl(cx, tcx, did)),
decoder::DlDef(ast::DefMod(did)) => {
csearch::each_child_of_item(&tcx.sess.cstore,
did,
|def, _, _| {
populate_impls(tcx, def, impls)
populate_impls(cx, tcx, def, impls)
})
}
_ => {}
@ -243,18 +252,26 @@ fn build_impls(cx: &core::DocContext,
}
}
impls
impls.move_iter().filter_map(|a| a).collect()
}
fn build_impl(tcx: &ty::ctxt, did: ast::DefId) -> clean::Item {
fn build_impl(cx: &core::DocContext,
tcx: &ty::ctxt,
did: ast::DefId) -> Option<clean::Item> {
if !cx.inlined.borrow_mut().get_mut_ref().insert(did) {
return None
}
let associated_trait = csearch::get_impl_trait(tcx, did);
let attrs = load_attrs(tcx, did);
let ty = ty::lookup_item_type(tcx, did);
let methods = csearch::get_impl_methods(&tcx.sess.cstore, did).iter().map(|did| {
let mut item = match ty::method(tcx, *did).clean() {
clean::Provided(item) => item,
clean::Required(item) => item,
};
let methods = csearch::get_impl_methods(&tcx.sess.cstore,
did).iter().filter_map(|did| {
let method = ty::method(tcx, *did);
if method.vis != ast::Public && associated_trait.is_none() {
return None
}
let mut item = ty::method(tcx, *did).clean();
item.inner = match item.inner.clone() {
clean::TyMethodItem(clean::TyMethod {
fn_style, decl, self_, generics
@ -268,9 +285,9 @@ fn build_impl(tcx: &ty::ctxt, did: ast::DefId) -> clean::Item {
}
_ => fail!("not a tymethod"),
};
item
Some(item)
}).collect();
clean::Item {
Some(clean::Item {
inner: clean::ImplItem(clean::Impl {
derived: clean::detect_derived(attrs.as_slice()),
trait_: associated_trait.clean().map(|bound| {
@ -288,7 +305,7 @@ fn build_impl(tcx: &ty::ctxt, did: ast::DefId) -> clean::Item {
attrs: attrs,
visibility: Some(ast::Inherited),
def_id: did,
}
})
}
fn build_module(cx: &core::DocContext, tcx: &ty::ctxt,

View File

@ -93,6 +93,7 @@ impl<'a> Clean<Crate> for visit_ast::RustdocVisitor<'a> {
cx.sess().cstore.iter_crate_data(|n, meta| {
externs.push((n, meta.clean()));
});
externs.sort_by(|&(a, _), &(b, _)| a.cmp(&b));
// Figure out the name of this crate
let input = driver::FileInput(cx.src.clone());
@ -132,24 +133,33 @@ impl<'a> Clean<Crate> for visit_ast::RustdocVisitor<'a> {
_ => unreachable!(),
};
let mut tmp = Vec::new();
for child in m.items.iter() {
match child.inner {
ModuleItem(..) => {},
for child in m.items.mut_iter() {
let inner = match child.inner {
ModuleItem(ref mut m) => m,
_ => continue,
}
};
let prim = match Primitive::find(child.attrs.as_slice()) {
Some(prim) => prim,
None => continue,
};
primitives.push(prim);
tmp.push(Item {
let mut i = Item {
source: Span::empty(),
name: Some(prim.to_url_str().to_string()),
attrs: child.attrs.clone(),
visibility: Some(ast::Public),
attrs: Vec::new(),
visibility: None,
def_id: ast_util::local_def(prim.to_node_id()),
inner: PrimitiveItem(prim),
});
};
// Push one copy to get indexed for the whole crate, and push a
// another copy in the proper location which will actually get
// documented. The first copy will also serve as a redirect to
// the other copy.
tmp.push(i.clone());
i.visibility = Some(ast::Public);
i.attrs = child.attrs.clone();
inner.items.push(i);
}
m.items.extend(tmp.move_iter());
}
@ -942,9 +952,8 @@ impl Clean<TraitMethod> for ast::TraitMethod {
}
}
impl Clean<TraitMethod> for ty::Method {
fn clean(&self) -> TraitMethod {
let m = if self.provided_source.is_some() {Provided} else {Required};
impl Clean<Item> for ty::Method {
fn clean(&self) -> Item {
let cx = super::ctxtkey.get().unwrap();
let tcx = match cx.maybe_typed {
core::Typed(ref tcx) => tcx,
@ -972,7 +981,7 @@ impl Clean<TraitMethod> for ty::Method {
}
};
m(Item {
Item {
name: Some(self.ident.clean()),
visibility: Some(ast::Inherited),
def_id: self.def_id,
@ -984,7 +993,7 @@ impl Clean<TraitMethod> for ty::Method {
self_: self_,
decl: (self.def_id, &sig).clean(),
})
})
}
}
}

View File

@ -108,6 +108,7 @@ pub enum ExternalLocation {
/// Metadata about an implementor of a trait.
pub struct Implementor {
def_id: ast::DefId,
generics: clean::Generics,
trait_: clean::Type,
for_: clean::Type,
@ -531,6 +532,11 @@ fn write_shared(cx: &Context,
try!(write!(&mut f, r"implementors['{}'] = [", krate.name));
for imp in imps.iter() {
// If the trait and implementation are in the same crate, then
// there's no need to emit information about it (there's inlining
// going on). If they're in different crates then the crate defining
// the trait will be interested in our implementation.
if imp.def_id.krate == did.krate { continue }
try!(write!(&mut f, r#""impl{} {} for {}","#,
imp.generics, imp.trait_, imp.for_));
}
@ -759,6 +765,7 @@ impl DocFolder for Cache {
Vec::new()
});
v.push(Implementor {
def_id: item.def_id,
generics: i.generics.clone(),
trait_: i.trait_.get_ref().clone(),
for_: i.for_.clone(),
@ -860,6 +867,12 @@ impl DocFolder for Cache {
stack.pop();
self.paths.insert(item.def_id, (stack, item_type::Enum));
}
clean::PrimitiveItem(..) if item.visibility.is_some() => {
self.paths.insert(item.def_id, (self.stack.clone(),
shortty(&item)));
}
_ => {}
}
@ -1075,21 +1088,21 @@ impl Context {
writer.flush()
}
// Private modules may survive the strip-private pass if they
// contain impls for public types. These modules can also
// contain items such as publicly reexported structures.
//
// External crates will provide links to these structures, so
// these modules are recursed into, but not rendered normally (a
// flag on the context).
if !self.render_redirect_pages {
self.render_redirect_pages = ignore_private_item(&item);
}
match item.inner {
// modules are special because they add a namespace. We also need to
// recurse into the items of the module as well.
clean::ModuleItem(..) => {
// Private modules may survive the strip-private pass if they
// contain impls for public types. These modules can also
// contain items such as publicly reexported structures.
//
// External crates will provide links to these structures, so
// these modules are recursed into, but not rendered normally (a
// flag on the context).
if !self.render_redirect_pages {
self.render_redirect_pages = ignore_private_module(&item);
}
let name = item.name.get_ref().to_string();
let mut item = Some(item);
self.recurse(name, |this| {
@ -1323,7 +1336,7 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
item: &clean::Item, items: &[clean::Item]) -> fmt::Result {
try!(document(w, item));
let mut indices = range(0, items.len()).filter(|i| {
!ignore_private_module(&items[*i])
!ignore_private_item(&items[*i])
}).collect::<Vec<uint>>();
fn cmp(i1: &clean::Item, i2: &clean::Item, idx1: uint, idx2: uint) -> Ordering {
@ -2009,7 +2022,7 @@ impl<'a> fmt::Show for Sidebar<'a> {
fn build_sidebar(m: &clean::Module) -> HashMap<String, Vec<String>> {
let mut map = HashMap::new();
for item in m.items.iter() {
if ignore_private_module(item) { continue }
if ignore_private_item(item) { continue }
let short = shortty(item).to_static_str();
let myname = match item.name {
@ -2059,12 +2072,13 @@ fn item_primitive(w: &mut fmt::Formatter,
render_methods(w, it)
}
fn ignore_private_module(it: &clean::Item) -> bool {
fn ignore_private_item(it: &clean::Item) -> bool {
match it.inner {
clean::ModuleItem(ref m) => {
(m.items.len() == 0 && it.doc_value().is_none()) ||
it.visibility != Some(ast::Public)
}
clean::PrimitiveItem(..) => it.visibility != Some(ast::Public),
_ => false,
}
}

View File

@ -664,7 +664,10 @@
for (var j = 0; j < structs.length; j++) {
var code = $('<code>').append(structs[j]);
$.each(code.find('a'), function(idx, a) {
$(a).attr('href', rootPath + $(a).attr('href'));
var href = $(a).attr('href');
if (!href.startsWith('http')) {
$(a).attr('href', rootPath + $(a).attr('href'));
}
});
var li = $('<li>').append(code);
list.append(li);