Skip to content

rustdoc: Render associated type bindings #20725

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

Merged
merged 1 commit into from
Jan 8, 2015
Merged
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
25 changes: 23 additions & 2 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,8 @@ fn external_path_params(cx: &DocContext, trait_did: Option<ast::DefId>,
_ => {
return PathParameters::AngleBracketed {
lifetimes: lifetimes,
types: types.clean(cx)
types: types.clean(cx),
bindings: vec![]
}
}
};
Expand All @@ -547,6 +548,7 @@ fn external_path_params(cx: &DocContext, trait_did: Option<ast::DefId>,
PathParameters::AngleBracketed {
lifetimes: lifetimes,
types: types.clean(cx),
bindings: vec![] // FIXME(#20646)
}
}
}
Expand Down Expand Up @@ -1766,6 +1768,7 @@ pub enum PathParameters {
AngleBracketed {
lifetimes: Vec<Lifetime>,
types: Vec<Type>,
bindings: Vec<TypeBinding>
},
Parenthesized {
inputs: Vec<Type>,
Expand All @@ -1779,7 +1782,8 @@ impl Clean<PathParameters> for ast::PathParameters {
ast::AngleBracketedParameters(ref data) => {
PathParameters::AngleBracketed {
lifetimes: data.lifetimes.clean(cx),
types: data.types.clean(cx)
types: data.types.clean(cx),
bindings: data.bindings.clean(cx)
}
}

Expand Down Expand Up @@ -2442,8 +2446,25 @@ fn lang_struct(cx: &DocContext, did: Option<ast::DefId>,
params: PathParameters::AngleBracketed {
lifetimes: vec![],
types: vec![t.clean(cx)],
bindings: vec![]
}
}],
},
}
}

/// An equality constraint on an associated type, e.g. `A=Bar` in `Foo<A=Bar>`
#[derive(Clone, PartialEq, RustcDecodable, RustcEncodable)]
pub struct TypeBinding {
pub name: String,
pub ty: Type
}

impl Clean<TypeBinding> for ast::TypeBinding {
fn clean(&self, cx: &DocContext) -> TypeBinding {
TypeBinding {
name: self.ident.clean(cx),
ty: self.ty.clean(cx)
}
}
}
27 changes: 25 additions & 2 deletions src/librustdoc/html/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,10 @@ impl fmt::Show for clean::PathParameters {
impl fmt::String for clean::PathParameters {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
clean::PathParameters::AngleBracketed { ref lifetimes, ref types } => {
if lifetimes.len() > 0 || types.len() > 0 {
clean::PathParameters::AngleBracketed {
ref lifetimes, ref types, ref bindings
} => {
if lifetimes.len() > 0 || types.len() > 0 || bindings.len() > 0 {
try!(f.write_str("&lt;"));
let mut comma = false;
for lifetime in lifetimes.iter() {
Expand All @@ -268,6 +270,13 @@ impl fmt::String for clean::PathParameters {
comma = true;
try!(write!(f, "{}", *ty));
}
for binding in bindings.iter() {
if comma {
try!(f.write_str(", "));
}
comma = true;
try!(write!(f, "{}", *binding));
}
try!(f.write_str("&gt;"));
}
}
Expand Down Expand Up @@ -855,6 +864,7 @@ impl fmt::String for clean::ViewListIdent {
params: clean::PathParameters::AngleBracketed {
lifetimes: Vec::new(),
types: Vec::new(),
bindings: Vec::new()
}
})
};
Expand All @@ -865,6 +875,19 @@ impl fmt::String for clean::ViewListIdent {
}
}

//NOTE(stage0): remove impl after snapshot
impl fmt::Show for clean::TypeBinding {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::String::fmt(self, f)
}
}

impl fmt::String for clean::TypeBinding {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}={}", self.name, self.ty)
}
}

//NOTE(stage0): remove impl after snapshot
#[cfg(stage0)]
impl fmt::Show for MutableSpace {
Expand Down