Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustdoc: Inline static documentation across crates #14687

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ fn try_inline_def(cx: &core::DocContext,
record_extern_fqn(cx, did, clean::TypeModule);
clean::ModuleItem(build_module(cx, tcx, did))
}
ast::DefStatic(did, mtbl) => {
record_extern_fqn(cx, did, clean::TypeStatic);
clean::StaticItem(build_static(tcx, did, mtbl))
}
_ => return None,
};
let fqn = csearch::get_item_path(tcx, did);
Expand Down Expand Up @@ -342,3 +346,13 @@ fn build_module(cx: &core::DocContext, tcx: &ty::ctxt,
is_crate: false,
}
}

fn build_static(tcx: &ty::ctxt,
did: ast::DefId,
mutable: bool) -> clean::Static {
clean::Static {
type_: ty::lookup_item_type(tcx, did).ty.clean(),
mutability: if mutable {clean::Mutable} else {clean::Immutable},
expr: "\n\n\n".to_string(), // trigger the "[definition]" links
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eurgh... :/

}
}
41 changes: 19 additions & 22 deletions src/librustdoc/html/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ pub struct VisSpace(pub Option<ast::Visibility>);
pub struct FnStyleSpace(pub ast::FnStyle);
/// Wrapper struct for properly emitting a method declaration.
pub struct Method<'a>(pub &'a clean::SelfTy, pub &'a clean::FnDecl);
/// Similar to VisSpace, but used for mutability
pub struct MutableSpace(pub clean::Mutability);

impl VisSpace {
pub fn get(&self) -> Option<ast::Visibility> {
Expand Down Expand Up @@ -438,24 +440,14 @@ impl fmt::Show for clean::Type {
clean::Unique(ref t) => write!(f, "~{}", **t),
clean::Managed(ref t) => write!(f, "@{}", **t),
clean::RawPointer(m, ref t) => {
write!(f, "*{}{}",
match m {
clean::Mutable => "mut ",
clean::Immutable => "",
}, **t)
write!(f, "*{}{}", MutableSpace(m), **t)
}
clean::BorrowedRef{ lifetime: ref l, mutability, type_: ref ty} => {
let lt = match *l {
Some(ref l) => format!("{} ", *l),
_ => "".to_string(),
};
write!(f, "&amp;{}{}{}",
lt,
match mutability {
clean::Mutable => "mut ",
clean::Immutable => "",
},
**ty)
write!(f, "&amp;{}{}{}", lt, MutableSpace(mutability), **ty)
}
}
}
Expand Down Expand Up @@ -494,17 +486,13 @@ impl<'a> fmt::Show for Method<'a> {
clean::SelfStatic => {},
clean::SelfValue => args.push_str("self"),
clean::SelfOwned => args.push_str("~self"),
clean::SelfBorrowed(Some(ref lt), clean::Immutable) => {
args.push_str(format!("&amp;{} self", *lt).as_slice());
}
clean::SelfBorrowed(Some(ref lt), clean::Mutable) => {
args.push_str(format!("&amp;{} mut self", *lt).as_slice());
}
clean::SelfBorrowed(None, clean::Mutable) => {
args.push_str("&amp;mut self");
clean::SelfBorrowed(Some(ref lt), mtbl) => {
args.push_str(format!("&amp;{} {}self", *lt,
MutableSpace(mtbl)).as_slice());
}
clean::SelfBorrowed(None, clean::Immutable) => {
args.push_str("&amp;self");
clean::SelfBorrowed(None, mtbl) => {
args.push_str(format!("&amp;{}self",
MutableSpace(mtbl)).as_slice());
}
}
for (i, input) in d.inputs.values.iter().enumerate() {
Expand Down Expand Up @@ -605,3 +593,12 @@ impl fmt::Show for clean::ViewListIdent {
}
}
}

impl fmt::Show for MutableSpace {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
MutableSpace(clean::Immutable) => Ok(()),
MutableSpace(clean::Mutable) => write!(f, "mut "),
}
}
}
5 changes: 3 additions & 2 deletions src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ use rustc::util::nodemap::NodeSet;
use clean;
use doctree;
use fold::DocFolder;
use html::format::{VisSpace, Method, FnStyleSpace};
use html::format::{VisSpace, Method, FnStyleSpace, MutableSpace};
use html::highlight;
use html::item_type::{ItemType, shortty};
use html::item_type;
Expand Down Expand Up @@ -1441,11 +1441,12 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,

try!(write!(w, "
<tr>
<td><code>{}static {}: {}</code>{}</td>
<td><code>{}static {}{}: {}</code>{}</td>
<td class='docblock'>{}&nbsp;</td>
</tr>
",
VisSpace(myitem.visibility),
MutableSpace(s.mutability),
*myitem.name.get_ref(),
s.type_,
Initializer(s.expr.as_slice(), Item { cx: cx, item: myitem }),
Expand Down