}
}
-impl<'tcx> Clean<TyParam> for ty::TypeParameterDef<'tcx> {
+impl<'tcx> Clean<TyParam> for ty::TypeParameterDef {
fn clean(&self, cx: &DocContext) -> TyParam {
cx.renderinfo.borrow_mut().external_typarams.insert(self.def_id, self.name.clean(cx));
TyParam {
name: self.name.clean(cx),
did: self.def_id,
bounds: vec![], // these are filled in from the where-clauses
- default: self.default.clean(cx),
+ default: if self.has_default {
+ Some(cx.tcx.item_type(self.def_id).clean(cx))
+ } else {
+ None
+ }
}
}
}
}
}
-impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics<'tcx>,
+impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics,
&'a ty::GenericPredicates<'tcx>) {
fn clean(&self, cx: &DocContext) -> Generics {
use self::WherePredicate as WP;
}
}
-impl<'a, 'tcx> Clean<FnDecl> for (DefId, &'a ty::PolyFnSig<'tcx>) {
+impl<'a, 'tcx> Clean<FnDecl> for (DefId, ty::PolyFnSig<'tcx>) {
fn clean(&self, cx: &DocContext) -> FnDecl {
let (did, sig) = *self;
let mut names = if cx.tcx.hir.as_local_node_id(did).is_some() {
ty::AssociatedKind::Method => {
let generics = (cx.tcx.item_generics(self.def_id),
&cx.tcx.item_predicates(self.def_id)).clean(cx);
- let fty = match cx.tcx.item_type(self.def_id).sty {
- ty::TyFnDef(_, _, f) => f,
- _ => unreachable!()
- };
- let mut decl = (self.def_id, &fty.sig).clean(cx);
+ let sig = cx.tcx.item_type(self.def_id).fn_sig();
+ let mut decl = (self.def_id, sig).clean(cx);
if self.method_has_self_argument {
let self_ty = match self.container {
}
ty::TraitContainer(_) => cx.tcx.mk_self_type()
};
- let self_arg_ty = *fty.sig.input(0).skip_binder();
+ let self_arg_ty = *sig.input(0).skip_binder();
if self_arg_ty == self_ty {
decl.inputs.values[0].type_ = Generic(String::from("Self"));
} else if let ty::TyRef(_, mt) = self_arg_ty.sty {
};
if provided {
MethodItem(Method {
- unsafety: fty.unsafety,
+ unsafety: sig.unsafety(),
generics: generics,
decl: decl,
- abi: fty.abi,
+ abi: sig.abi(),
// trait methods canot (currently, at least) be const
constness: hir::Constness::NotConst,
})
} else {
TyMethodItem(TyMethod {
- unsafety: fty.unsafety,
+ unsafety: sig.unsafety(),
generics: generics,
decl: decl,
- abi: fty.abi,
+ abi: sig.abi(),
})
}
}
/// A representation of a Type suitable for hyperlinking purposes. Ideally one can get the original
/// type out of the AST/TyCtxt given one of these, if more information is needed. Most importantly
/// it does not preserve mutability or boxes.
- #[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Debug)]
+ #[derive(Clone, RustcEncodable, RustcDecodable, PartialEq)]
pub enum Type {
/// structs/enums/traits (most that'd be an hir::TyPath)
ResolvedPath {
}
TyPath(hir::QPath::TypeRelative(ref qself, ref segment)) => {
let mut def = Def::Err;
- if let Some(ty) = cx.hir_ty_to_ty.get(&self.id) {
+ if let Some(ty) = cx.tcx.ast_ty_to_ty_cache.borrow().get(&self.id) {
if let ty::TyProjection(proj) = ty.sty {
def = Def::Trait(proj.trait_ref.def_id);
}
mutability: mt.mutbl.clean(cx),
type_: box mt.ty.clean(cx),
},
- ty::TyFnDef(.., ref fty) |
- ty::TyFnPtr(ref fty) => BareFunction(box BareFunctionDecl {
- unsafety: fty.unsafety,
+ ty::TyFnDef(.., sig) |
+ ty::TyFnPtr(sig) => BareFunction(box BareFunctionDecl {
+ unsafety: sig.unsafety(),
generics: Generics {
lifetimes: Vec::new(),
type_params: Vec::new(),
where_predicates: Vec::new()
},
- decl: (cx.tcx.hir.local_def_id(ast::CRATE_NODE_ID), &fty.sig).clean(cx),
- abi: fty.abi,
+ decl: (cx.tcx.hir.local_def_id(ast::CRATE_NODE_ID), sig).clean(cx),
+ abi: sig.abi(),
}),
ty::TyAdt(def, substs) => {
let did = def.did;
component)?;
}
}
- write!(fmt, "<a class='{}' href=''>{}</a>",
+ write!(fmt, "<a class=\"{}\" href=''>{}</a>",
self.item.type_(), self.item.name.as_ref().unwrap())?;
write!(fmt, "</span>")?; // in-band
Ok(())
}
+ fn md_render_assoc_item(item: &clean::Item) -> String {
+ match item.inner {
+ clean::AssociatedConstItem(ref ty, ref default) => {
+ if let Some(default) = default.as_ref() {
+ format!("```\n{}: {:?} = {}\n```\n\n", item.name.as_ref().unwrap(), ty, default)
+ } else {
+ format!("```\n{}: {:?}\n```\n\n", item.name.as_ref().unwrap(), ty)
+ }
+ }
+ _ => String::new(),
+ }
+ }
+
+ fn get_doc_value(item: &clean::Item) -> Option<&str> {
+ let x = item.doc_value();
+ if x.is_none() {
+ match item.inner {
+ clean::AssociatedConstItem(_, _) => Some(""),
+ _ => None,
+ }
+ } else {
+ x
+ }
+ }
+
fn document_full(w: &mut fmt::Formatter, item: &clean::Item) -> fmt::Result {
- if let Some(s) = item.doc_value() {
- write!(w, "<div class='docblock'>{}</div>", Markdown(s))?;
+ if let Some(s) = get_doc_value(item) {
+ write!(w, "<div class='docblock'>{}</div>",
+ Markdown(&format!("{}{}", md_render_assoc_item(item), s)))?;
}
Ok(())
}
let doc_value = myitem.doc_value().unwrap_or("");
write!(w, "
<tr class='{stab} module-item'>
- <td><a class='{class}' href='{href}'
+ <td><a class=\"{class}\" href=\"{href}\"
title='{title_type} {title}'>{name}</a>{unsafety_flag}</td>
<td class='docblock-short'>
{stab_docs} {docs}
&cx.shared.issue_tracker_base_url,
stab.issue) {
(true, &Some(ref tracker_url), Some(issue_no)) if issue_no > 0 =>
- format!(" (<code>{}</code> <a href=\"{}{}\">#{}</a>)",
+ format!(" (<code>{} </code><a href=\"{}{}\">#{}</a>)",
Escape(&stab.feature), tracker_url, issue_no, issue_no),
(false, &Some(ref tracker_url), Some(issue_no)) if issue_no > 0 =>
format!(" (<a href=\"{}{}\">#{}</a>)", Escape(&tracker_url), issue_no,
if stab.unstable_reason.is_empty() {
stability.push(format!("<div class='stab unstable'>\
<span class=microscope>🔬</span> \
- This is a nightly-only experimental API. {}\
+ This is a nightly-only experimental API. {}\
</div>",
- unstable_extra));
+ unstable_extra));
} else {
let text = format!("<summary><span class=microscope>🔬</span> \
- This is a nightly-only experimental API. {}\
+ This is a nightly-only experimental API. {}\
</summary>{}",
unstable_extra, MarkdownHtml(&stab.unstable_reason));
stability.push(format!("<div class='stab unstable'><details>{}</details></div>",
fn assoc_const(w: &mut fmt::Formatter,
it: &clean::Item,
ty: &clean::Type,
- default: Option<&String>,
+ _default: Option<&String>,
link: AssocItemLink) -> fmt::Result {
- write!(w, "const <a href='{}' class='constant'>{}</a>",
+ write!(w, "const <a href='{}' class=\"constant\"><b>{}</b></a>: {}",
naive_assoc_href(it, link),
- it.name.as_ref().unwrap())?;
-
- write!(w, ": {}", ty)?;
- if let Some(default) = default {
- write!(w, " = {}", Escape(default))?;
- }
+ it.name.as_ref().unwrap(),
+ ty)?;
Ok(())
}
bounds: &Vec<clean::TyParamBound>,
default: Option<&clean::Type>,
link: AssocItemLink) -> fmt::Result {
- write!(w, "type <a href='{}' class='type'>{}</a>",
+ write!(w, "type <a href='{}' class=\"type\">{}</a>",
naive_assoc_href(it, link),
it.name.as_ref().unwrap())?;
if !bounds.is_empty() {
let ns_id = derive_id(format!("{}.{}",
field.name.as_ref().unwrap(),
ItemType::StructField.name_space()));
- write!(w, "<span id='{id}' class='{item_type}'>
+ write!(w, "<span id='{id}' class=\"{item_type}\">
<span id='{ns_id}' class='invisible'>
<code>{name}: {ty}</code>
</span></span>",
if fields.peek().is_some() {
write!(w, "<h2 class='fields'>Fields</h2>")?;
for (field, ty) in fields {
- write!(w, "<span id='{shortty}.{name}' class='{shortty}'><code>{name}: {ty}</code>
+ write!(w, "<span id='{shortty}.{name}' class=\"{shortty}\"><code>{name}: {ty}</code>
</span>",
shortty = ItemType::StructField,
name = field.name.as_ref().unwrap(),
if render_method_item {
let id = derive_id(format!("{}.{}", item_type, name));
let ns_id = derive_id(format!("{}.{}", name, item_type.name_space()));
- write!(w, "<h4 id='{}' class='{}'>", id, item_type)?;
+ write!(w, "<h4 id='{}' class=\"{}\">", id, item_type)?;
write!(w, "<span id='{}' class='invisible'>", ns_id)?;
write!(w, "<code>")?;
render_assoc_item(w, item, link.anchor(&id), ItemType::Impl)?;
clean::TypedefItem(ref tydef, _) => {
let id = derive_id(format!("{}.{}", ItemType::AssociatedType, name));
let ns_id = derive_id(format!("{}.{}", name, item_type.name_space()));
- write!(w, "<h4 id='{}' class='{}'>", id, item_type)?;
+ write!(w, "<h4 id='{}' class=\"{}\">", id, item_type)?;
write!(w, "<span id='{}' class='invisible'><code>", ns_id)?;
assoc_type(w, item, &Vec::new(), Some(&tydef.type_), link.anchor(&id))?;
write!(w, "</code></span></h4>\n")?;
clean::AssociatedConstItem(ref ty, ref default) => {
let id = derive_id(format!("{}.{}", item_type, name));
let ns_id = derive_id(format!("{}.{}", name, item_type.name_space()));
- write!(w, "<h4 id='{}' class='{}'>", id, item_type)?;
+ write!(w, "<h4 id='{}' class=\"{}\">", id, item_type)?;
write!(w, "<span id='{}' class='invisible'><code>", ns_id)?;
assoc_const(w, item, ty, default.as_ref(), link.anchor(&id))?;
write!(w, "</code></span></h4>\n")?;
clean::ConstantItem(ref c) => {
let id = derive_id(format!("{}.{}", item_type, name));
let ns_id = derive_id(format!("{}.{}", name, item_type.name_space()));
- write!(w, "<h4 id='{}' class='{}'>", id, item_type)?;
+ write!(w, "<h4 id='{}' class=\"{}\">", id, item_type)?;
write!(w, "<span id='{}' class='invisible'><code>", ns_id)?;
assoc_const(w, item, &c.type_, Some(&c.expr), link.anchor(&id))?;
write!(w, "</code></span></h4>\n")?;
clean::AssociatedTypeItem(ref bounds, ref default) => {
let id = derive_id(format!("{}.{}", item_type, name));
let ns_id = derive_id(format!("{}.{}", name, item_type.name_space()));
- write!(w, "<h4 id='{}' class='{}'>", id, item_type)?;
+ write!(w, "<h4 id='{}' class=\"{}\">", id, item_type)?;
write!(w, "<span id='{}' class='invisible'><code>", ns_id)?;
assoc_type(w, item, bounds, default.as_ref(), link.anchor(&id))?;
write!(w, "</code></span></h4>\n")?;
// We need the stability of the item from the trait
// because impls can't have a stability.
document_stability(w, cx, it)?;
- if item.doc_value().is_some() {
+ if get_doc_value(item).is_some() {
document_full(w, item)?;
} else {
// In case the item isn't documented,