Skip to content

Commit 073c8f1

Browse files
committed
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).
2 parents 422d54b + 1827241 commit 073c8f1

File tree

7 files changed

+122
-54
lines changed

7 files changed

+122
-54
lines changed

mk/docs.mk

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ HTML_DEPS += doc/version_info.html
110110
doc/version_info.html: $(D)/version_info.html.template $(MKFILE_DEPS) \
111111
$(wildcard $(D)/*.*) | doc/
112112
@$(call E, version-info: $@)
113-
sed -e "s/VERSION/$(CFG_RELEASE)/; s/SHORT_HASH/$(shell echo \
113+
$(Q)sed -e "s/VERSION/$(CFG_RELEASE)/; s/SHORT_HASH/$(shell echo \
114114
$(CFG_VER_HASH) | head -c 8)/;\
115115
s/STAMP/$(CFG_VER_HASH)/;" $< >$@
116116

@@ -156,15 +156,17 @@ doc/footer.tex: $(D)/footer.inc | doc/
156156
# HTML (rustdoc)
157157
DOC_TARGETS += doc/not_found.html
158158
doc/not_found.html: $(D)/not_found.md $(HTML_DEPS) | doc/
159-
$(RUSTDOC) $(RUSTDOC_HTML_OPTS_NO_CSS) --markdown-css http://doc.rust-lang.org/rust.css $<
159+
@$(call E, rustdoc: $@)
160+
$(Q)$(RUSTDOC) $(RUSTDOC_HTML_OPTS_NO_CSS) \
161+
--markdown-css http://doc.rust-lang.org/rust.css $<
160162

161163
define DEF_DOC
162164

163165
# HTML (rustdoc)
164166
DOC_TARGETS += doc/$(1).html
165167
doc/$(1).html: $$(D)/$(1).md $$(HTML_DEPS) $$(RUSTDOC_DEPS_$(1)) | doc/
166168
@$$(call E, rustdoc: $$@)
167-
$$(RUSTDOC) $$(RUSTDOC_HTML_OPTS) $$(RUSTDOC_FLAGS_$(1)) $$<
169+
$$(Q)$$(RUSTDOC) $$(RUSTDOC_HTML_OPTS) $$(RUSTDOC_FLAGS_$(1)) $$<
168170

169171
ifneq ($(ONLY_HTML_DOCS),1)
170172

src/doc/index.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ li {list-style-type: none; }
6161
* [The `time` library](time/index.html)
6262
* [The `uuid` 128-bit universally unique identifier library](uuid/index.html)
6363
* [The `url` library](url/index.html)
64-
* [The `workcache` library](workcache/index.html)
6564
* [The `log` library](log/index.html)
6665

6766
# Tooling

src/libcore/fmt/rt.rs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,24 @@
1414
//! These definitions are similar to their `ct` equivalents, but differ in that
1515
//! these can be statically allocated and are slightly optimized for the runtime
1616
17-
#![allow(missing_doc)]
18-
#![doc(hidden)]
19-
2017
use option::Option;
2118

19+
#[doc(hidden)]
2220
pub enum Piece<'a> {
2321
String(&'a str),
2422
// FIXME(#8259): this shouldn't require the unit-value here
2523
CurrentArgument(()),
2624
Argument(Argument<'a>),
2725
}
2826

27+
#[doc(hidden)]
2928
pub struct Argument<'a> {
3029
pub position: Position,
3130
pub format: FormatSpec,
3231
pub method: Option<&'a Method<'a>>
3332
}
3433

34+
#[doc(hidden)]
3535
pub struct FormatSpec {
3636
pub fill: char,
3737
pub align: Alignment,
@@ -40,38 +40,60 @@ pub struct FormatSpec {
4040
pub width: Count,
4141
}
4242

43+
/// Possible alignments that can be requested as part of a formatting directive.
4344
#[deriving(PartialEq)]
4445
pub enum Alignment {
46+
/// Indication that contents should be left-aligned.
4547
AlignLeft,
48+
/// Indication that contents should be right-aligned.
4649
AlignRight,
50+
/// No alignment was requested.
4751
AlignUnknown,
4852
}
4953

54+
#[doc(hidden)]
5055
pub enum Count {
5156
CountIs(uint), CountIsParam(uint), CountIsNextParam, CountImplied,
5257
}
5358

59+
#[doc(hidden)]
5460
pub enum Position {
5561
ArgumentNext, ArgumentIs(uint)
5662
}
5763

64+
/// Flags which can be passed to formatting via a directive.
65+
///
66+
/// These flags are discovered through the `flags` field of the `Formatter`
67+
/// structure. The flag in that structure is a union of these flags into a
68+
/// `uint` where each flag's discriminant is the corresponding bit.
5869
pub enum Flag {
70+
/// A flag which enables number formatting to always print the sign of a
71+
/// number.
5972
FlagSignPlus,
73+
/// Currently not a used flag
6074
FlagSignMinus,
75+
/// Indicates that the "alternate formatting" for a type should be used.
76+
///
77+
/// The meaning of this flag is type-specific.
6178
FlagAlternate,
79+
/// Indicates that padding should be done with a `0` character as well as
80+
/// being aware of the sign to be printed.
6281
FlagSignAwareZeroPad,
6382
}
6483

84+
#[doc(hidden)]
6585
pub enum Method<'a> {
6686
Plural(Option<uint>, &'a [PluralArm<'a>], &'a [Piece<'a>]),
6787
Select(&'a [SelectArm<'a>], &'a [Piece<'a>]),
6888
}
6989

90+
#[doc(hidden)]
7091
pub enum PluralSelector {
7192
Keyword(PluralKeyword),
7293
Literal(uint),
7394
}
7495

96+
#[doc(hidden)]
7597
pub enum PluralKeyword {
7698
Zero,
7799
One,
@@ -80,11 +102,13 @@ pub enum PluralKeyword {
80102
Many,
81103
}
82104

105+
#[doc(hidden)]
83106
pub struct PluralArm<'a> {
84107
pub selector: PluralSelector,
85108
pub result: &'a [Piece<'a>],
86109
}
87110

111+
#[doc(hidden)]
88112
pub struct SelectArm<'a> {
89113
pub selector: &'a str,
90114
pub result: &'a [Piece<'a>],

src/librustdoc/clean/inline.rs

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ pub fn record_extern_fqn(cx: &core::DocContext,
129129
match cx.maybe_typed {
130130
core::Typed(ref tcx) => {
131131
let fqn = csearch::get_item_path(tcx, did);
132-
let fqn = fqn.move_iter().map(|i| i.to_str().to_string()).collect();
132+
let fqn = fqn.move_iter().map(|i| i.to_str()).collect();
133133
cx.external_paths.borrow_mut().get_mut_ref().insert(did, (fqn, kind));
134134
}
135135
core::NotTyped(..) => {}
@@ -138,10 +138,18 @@ pub fn record_extern_fqn(cx: &core::DocContext,
138138

139139
pub fn build_external_trait(tcx: &ty::ctxt, did: ast::DefId) -> clean::Trait {
140140
let def = ty::lookup_trait_def(tcx, did);
141-
let methods = ty::trait_methods(tcx, did);
141+
let methods = ty::trait_methods(tcx, did).clean();
142+
let provided = ty::provided_trait_methods(tcx, did);
143+
let mut methods = methods.move_iter().map(|meth| {
144+
if provided.iter().any(|a| a.def_id == meth.def_id) {
145+
clean::Provided(meth)
146+
} else {
147+
clean::Required(meth)
148+
}
149+
});
142150
clean::Trait {
143151
generics: def.generics.clean(),
144-
methods: methods.iter().map(|i| i.clean()).collect(),
152+
methods: methods.collect(),
145153
parents: Vec::new(), // FIXME: this is likely wrong
146154
}
147155
}
@@ -207,7 +215,7 @@ fn build_impls(cx: &core::DocContext,
207215
match tcx.inherent_impls.borrow().find(&did) {
208216
None => {}
209217
Some(i) => {
210-
impls.extend(i.borrow().iter().map(|&did| { build_impl(tcx, did) }));
218+
impls.extend(i.borrow().iter().map(|&did| { build_impl(cx, tcx, did) }));
211219
}
212220
}
213221

@@ -223,38 +231,47 @@ fn build_impls(cx: &core::DocContext,
223231
csearch::each_top_level_item_of_crate(&tcx.sess.cstore,
224232
did.krate,
225233
|def, _, _| {
226-
populate_impls(tcx, def, &mut impls)
234+
populate_impls(cx, tcx, def, &mut impls)
227235
});
228236

229-
fn populate_impls(tcx: &ty::ctxt,
237+
fn populate_impls(cx: &core::DocContext,
238+
tcx: &ty::ctxt,
230239
def: decoder::DefLike,
231-
impls: &mut Vec<clean::Item>) {
240+
impls: &mut Vec<Option<clean::Item>>) {
232241
match def {
233-
decoder::DlImpl(did) => impls.push(build_impl(tcx, did)),
242+
decoder::DlImpl(did) => impls.push(build_impl(cx, tcx, did)),
234243
decoder::DlDef(ast::DefMod(did)) => {
235244
csearch::each_child_of_item(&tcx.sess.cstore,
236245
did,
237246
|def, _, _| {
238-
populate_impls(tcx, def, impls)
247+
populate_impls(cx, tcx, def, impls)
239248
})
240249
}
241250
_ => {}
242251
}
243252
}
244253
}
245254

246-
impls
255+
impls.move_iter().filter_map(|a| a).collect()
247256
}
248257

249-
fn build_impl(tcx: &ty::ctxt, did: ast::DefId) -> clean::Item {
258+
fn build_impl(cx: &core::DocContext,
259+
tcx: &ty::ctxt,
260+
did: ast::DefId) -> Option<clean::Item> {
261+
if !cx.inlined.borrow_mut().get_mut_ref().insert(did) {
262+
return None
263+
}
264+
250265
let associated_trait = csearch::get_impl_trait(tcx, did);
251266
let attrs = load_attrs(tcx, did);
252267
let ty = ty::lookup_item_type(tcx, did);
253-
let methods = csearch::get_impl_methods(&tcx.sess.cstore, did).iter().map(|did| {
254-
let mut item = match ty::method(tcx, *did).clean() {
255-
clean::Provided(item) => item,
256-
clean::Required(item) => item,
257-
};
268+
let methods = csearch::get_impl_methods(&tcx.sess.cstore,
269+
did).iter().filter_map(|did| {
270+
let method = ty::method(tcx, *did);
271+
if method.vis != ast::Public && associated_trait.is_none() {
272+
return None
273+
}
274+
let mut item = ty::method(tcx, *did).clean();
258275
item.inner = match item.inner.clone() {
259276
clean::TyMethodItem(clean::TyMethod {
260277
fn_style, decl, self_, generics
@@ -268,9 +285,9 @@ fn build_impl(tcx: &ty::ctxt, did: ast::DefId) -> clean::Item {
268285
}
269286
_ => fail!("not a tymethod"),
270287
};
271-
item
288+
Some(item)
272289
}).collect();
273-
clean::Item {
290+
Some(clean::Item {
274291
inner: clean::ImplItem(clean::Impl {
275292
derived: clean::detect_derived(attrs.as_slice()),
276293
trait_: associated_trait.clean().map(|bound| {
@@ -288,7 +305,7 @@ fn build_impl(tcx: &ty::ctxt, did: ast::DefId) -> clean::Item {
288305
attrs: attrs,
289306
visibility: Some(ast::Inherited),
290307
def_id: did,
291-
}
308+
})
292309
}
293310

294311
fn build_module(cx: &core::DocContext, tcx: &ty::ctxt,

src/librustdoc/clean/mod.rs

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ impl<'a> Clean<Crate> for visit_ast::RustdocVisitor<'a> {
9393
cx.sess().cstore.iter_crate_data(|n, meta| {
9494
externs.push((n, meta.clean()));
9595
});
96+
externs.sort_by(|&(a, _), &(b, _)| a.cmp(&b));
9697

9798
// Figure out the name of this crate
9899
let input = driver::FileInput(cx.src.clone());
@@ -132,24 +133,33 @@ impl<'a> Clean<Crate> for visit_ast::RustdocVisitor<'a> {
132133
_ => unreachable!(),
133134
};
134135
let mut tmp = Vec::new();
135-
for child in m.items.iter() {
136-
match child.inner {
137-
ModuleItem(..) => {},
136+
for child in m.items.mut_iter() {
137+
let inner = match child.inner {
138+
ModuleItem(ref mut m) => m,
138139
_ => continue,
139-
}
140+
};
140141
let prim = match Primitive::find(child.attrs.as_slice()) {
141142
Some(prim) => prim,
142143
None => continue,
143144
};
144145
primitives.push(prim);
145-
tmp.push(Item {
146+
let mut i = Item {
146147
source: Span::empty(),
147148
name: Some(prim.to_url_str().to_string()),
148-
attrs: child.attrs.clone(),
149-
visibility: Some(ast::Public),
149+
attrs: Vec::new(),
150+
visibility: None,
150151
def_id: ast_util::local_def(prim.to_node_id()),
151152
inner: PrimitiveItem(prim),
152-
});
153+
};
154+
// Push one copy to get indexed for the whole crate, and push a
155+
// another copy in the proper location which will actually get
156+
// documented. The first copy will also serve as a redirect to
157+
// the other copy.
158+
tmp.push(i.clone());
159+
i.visibility = Some(ast::Public);
160+
i.attrs = child.attrs.clone();
161+
inner.items.push(i);
162+
153163
}
154164
m.items.extend(tmp.move_iter());
155165
}
@@ -942,9 +952,8 @@ impl Clean<TraitMethod> for ast::TraitMethod {
942952
}
943953
}
944954

945-
impl Clean<TraitMethod> for ty::Method {
946-
fn clean(&self) -> TraitMethod {
947-
let m = if self.provided_source.is_some() {Provided} else {Required};
955+
impl Clean<Item> for ty::Method {
956+
fn clean(&self) -> Item {
948957
let cx = super::ctxtkey.get().unwrap();
949958
let tcx = match cx.maybe_typed {
950959
core::Typed(ref tcx) => tcx,
@@ -972,7 +981,7 @@ impl Clean<TraitMethod> for ty::Method {
972981
}
973982
};
974983

975-
m(Item {
984+
Item {
976985
name: Some(self.ident.clean()),
977986
visibility: Some(ast::Inherited),
978987
def_id: self.def_id,
@@ -984,7 +993,7 @@ impl Clean<TraitMethod> for ty::Method {
984993
self_: self_,
985994
decl: (self.def_id, &sig).clean(),
986995
})
987-
})
996+
}
988997
}
989998
}
990999

0 commit comments

Comments
 (0)