Skip to content

Commit 06f3f9a

Browse files
committed
rustdoc: Inline static documentation across crates
1 parent 2290dbb commit 06f3f9a

File tree

3 files changed

+36
-24
lines changed

3 files changed

+36
-24
lines changed

src/librustdoc/clean/inline.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ fn try_inline_def(cx: &core::DocContext,
8888
record_extern_fqn(cx, did, clean::TypeModule);
8989
clean::ModuleItem(build_module(cx, tcx, did))
9090
}
91+
ast::DefStatic(did, mtbl) => {
92+
record_extern_fqn(cx, did, clean::TypeStatic);
93+
clean::StaticItem(build_static(tcx, did, mtbl))
94+
}
9195
_ => return None,
9296
};
9397
let fqn = csearch::get_item_path(tcx, did);
@@ -343,3 +347,13 @@ fn build_module(cx: &core::DocContext, tcx: &ty::ctxt,
343347
is_crate: false,
344348
}
345349
}
350+
351+
fn build_static(tcx: &ty::ctxt,
352+
did: ast::DefId,
353+
mutable: bool) -> clean::Static {
354+
clean::Static {
355+
type_: ty::lookup_item_type(tcx, did).ty.clean(),
356+
mutability: if mutable {clean::Mutable} else {clean::Immutable},
357+
expr: "\n\n\n".to_string(), // trigger the "[definition]" links
358+
}
359+
}

src/librustdoc/html/format.rs

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ pub struct VisSpace(pub Option<ast::Visibility>);
3535
pub struct FnStyleSpace(pub ast::FnStyle);
3636
/// Wrapper struct for properly emitting a method declaration.
3737
pub struct Method<'a>(pub &'a clean::SelfTy, pub &'a clean::FnDecl);
38+
/// Similar to VisSpace, but used for mutability
39+
pub struct MutableSpace(pub clean::Mutability);
3840

3941
impl VisSpace {
4042
pub fn get(&self) -> Option<ast::Visibility> {
@@ -438,24 +440,14 @@ impl fmt::Show for clean::Type {
438440
clean::Unique(ref t) => write!(f, "~{}", **t),
439441
clean::Managed(ref t) => write!(f, "@{}", **t),
440442
clean::RawPointer(m, ref t) => {
441-
write!(f, "*{}{}",
442-
match m {
443-
clean::Mutable => "mut ",
444-
clean::Immutable => "",
445-
}, **t)
443+
write!(f, "*{}{}", MutableSpace(m), **t)
446444
}
447445
clean::BorrowedRef{ lifetime: ref l, mutability, type_: ref ty} => {
448446
let lt = match *l {
449447
Some(ref l) => format!("{} ", *l),
450448
_ => "".to_string(),
451449
};
452-
write!(f, "&amp;{}{}{}",
453-
lt,
454-
match mutability {
455-
clean::Mutable => "mut ",
456-
clean::Immutable => "",
457-
},
458-
**ty)
450+
write!(f, "&amp;{}{}{}", lt, MutableSpace(mutability), **ty)
459451
}
460452
}
461453
}
@@ -494,17 +486,13 @@ impl<'a> fmt::Show for Method<'a> {
494486
clean::SelfStatic => {},
495487
clean::SelfValue => args.push_str("self"),
496488
clean::SelfOwned => args.push_str("~self"),
497-
clean::SelfBorrowed(Some(ref lt), clean::Immutable) => {
498-
args.push_str(format!("&amp;{} self", *lt).as_slice());
499-
}
500-
clean::SelfBorrowed(Some(ref lt), clean::Mutable) => {
501-
args.push_str(format!("&amp;{} mut self", *lt).as_slice());
502-
}
503-
clean::SelfBorrowed(None, clean::Mutable) => {
504-
args.push_str("&amp;mut self");
489+
clean::SelfBorrowed(Some(ref lt), mtbl) => {
490+
args.push_str(format!("&amp;{} {}self", *lt,
491+
MutableSpace(mtbl)).as_slice());
505492
}
506-
clean::SelfBorrowed(None, clean::Immutable) => {
507-
args.push_str("&amp;self");
493+
clean::SelfBorrowed(None, mtbl) => {
494+
args.push_str(format!("&amp;{}self",
495+
MutableSpace(mtbl)).as_slice());
508496
}
509497
}
510498
for (i, input) in d.inputs.values.iter().enumerate() {
@@ -605,3 +593,12 @@ impl fmt::Show for clean::ViewListIdent {
605593
}
606594
}
607595
}
596+
597+
impl fmt::Show for MutableSpace {
598+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
599+
match *self {
600+
MutableSpace(clean::Immutable) => Ok(()),
601+
MutableSpace(clean::Mutable) => write!(f, "mut "),
602+
}
603+
}
604+
}

src/librustdoc/html/render.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ use rustc::util::nodemap::NodeSet;
5151
use clean;
5252
use doctree;
5353
use fold::DocFolder;
54-
use html::format::{VisSpace, Method, FnStyleSpace};
54+
use html::format::{VisSpace, Method, FnStyleSpace, MutableSpace};
5555
use html::highlight;
5656
use html::item_type::{ItemType, shortty};
5757
use html::item_type;
@@ -1441,11 +1441,12 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
14411441

14421442
try!(write!(w, "
14431443
<tr>
1444-
<td><code>{}static {}: {}</code>{}</td>
1444+
<td><code>{}static {}{}: {}</code>{}</td>
14451445
<td class='docblock'>{}&nbsp;</td>
14461446
</tr>
14471447
",
14481448
VisSpace(myitem.visibility),
1449+
MutableSpace(s.mutability),
14491450
*myitem.name.get_ref(),
14501451
s.type_,
14511452
Initializer(s.expr.as_slice(), Item { cx: cx, item: myitem }),

0 commit comments

Comments
 (0)