Skip to content

Commit a0734ff

Browse files
committed
rustdoc: Render associated type bindings
e.g. `Foo<Output=A>` This does not work cross-crate unfortunately. Part of #20646
1 parent 9f1ead8 commit a0734ff

File tree

2 files changed

+48
-4
lines changed

2 files changed

+48
-4
lines changed

src/librustdoc/clean/mod.rs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,8 @@ fn external_path_params(cx: &DocContext, trait_did: Option<ast::DefId>,
530530
_ => {
531531
return PathParameters::AngleBracketed {
532532
lifetimes: lifetimes,
533-
types: types.clean(cx)
533+
types: types.clean(cx),
534+
bindings: vec![]
534535
}
535536
}
536537
};
@@ -547,6 +548,7 @@ fn external_path_params(cx: &DocContext, trait_did: Option<ast::DefId>,
547548
PathParameters::AngleBracketed {
548549
lifetimes: lifetimes,
549550
types: types.clean(cx),
551+
bindings: vec![] // FIXME(#20646)
550552
}
551553
}
552554
}
@@ -1766,6 +1768,7 @@ pub enum PathParameters {
17661768
AngleBracketed {
17671769
lifetimes: Vec<Lifetime>,
17681770
types: Vec<Type>,
1771+
bindings: Vec<TypeBinding>
17691772
},
17701773
Parenthesized {
17711774
inputs: Vec<Type>,
@@ -1779,7 +1782,8 @@ impl Clean<PathParameters> for ast::PathParameters {
17791782
ast::AngleBracketedParameters(ref data) => {
17801783
PathParameters::AngleBracketed {
17811784
lifetimes: data.lifetimes.clean(cx),
1782-
types: data.types.clean(cx)
1785+
types: data.types.clean(cx),
1786+
bindings: data.bindings.clean(cx)
17831787
}
17841788
}
17851789

@@ -2442,8 +2446,25 @@ fn lang_struct(cx: &DocContext, did: Option<ast::DefId>,
24422446
params: PathParameters::AngleBracketed {
24432447
lifetimes: vec![],
24442448
types: vec![t.clean(cx)],
2449+
bindings: vec![]
24452450
}
24462451
}],
24472452
},
24482453
}
24492454
}
2455+
2456+
/// An equality constraint on an associated type, e.g. `A=Bar` in `Foo<A=Bar>`
2457+
#[derive(Clone, PartialEq, RustcDecodable, RustcEncodable)]
2458+
pub struct TypeBinding {
2459+
pub name: String,
2460+
pub ty: Type
2461+
}
2462+
2463+
impl Clean<TypeBinding> for ast::TypeBinding {
2464+
fn clean(&self, cx: &DocContext) -> TypeBinding {
2465+
TypeBinding {
2466+
name: self.ident.clean(cx),
2467+
ty: self.ty.clean(cx)
2468+
}
2469+
}
2470+
}

src/librustdoc/html/format.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,10 @@ impl fmt::Show for clean::PathParameters {
250250
impl fmt::String for clean::PathParameters {
251251
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
252252
match *self {
253-
clean::PathParameters::AngleBracketed { ref lifetimes, ref types } => {
254-
if lifetimes.len() > 0 || types.len() > 0 {
253+
clean::PathParameters::AngleBracketed {
254+
ref lifetimes, ref types, ref bindings
255+
} => {
256+
if lifetimes.len() > 0 || types.len() > 0 || bindings.len() > 0 {
255257
try!(f.write_str("&lt;"));
256258
let mut comma = false;
257259
for lifetime in lifetimes.iter() {
@@ -268,6 +270,13 @@ impl fmt::String for clean::PathParameters {
268270
comma = true;
269271
try!(write!(f, "{}", *ty));
270272
}
273+
for binding in bindings.iter() {
274+
if comma {
275+
try!(f.write_str(", "));
276+
}
277+
comma = true;
278+
try!(write!(f, "{}", *binding));
279+
}
271280
try!(f.write_str("&gt;"));
272281
}
273282
}
@@ -855,6 +864,7 @@ impl fmt::String for clean::ViewListIdent {
855864
params: clean::PathParameters::AngleBracketed {
856865
lifetimes: Vec::new(),
857866
types: Vec::new(),
867+
bindings: Vec::new()
858868
}
859869
})
860870
};
@@ -865,6 +875,19 @@ impl fmt::String for clean::ViewListIdent {
865875
}
866876
}
867877

878+
//NOTE(stage0): remove impl after snapshot
879+
impl fmt::Show for clean::TypeBinding {
880+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
881+
fmt::String::fmt(self, f)
882+
}
883+
}
884+
885+
impl fmt::String for clean::TypeBinding {
886+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
887+
write!(f, "{}={}", self.name, self.ty)
888+
}
889+
}
890+
868891
//NOTE(stage0): remove impl after snapshot
869892
#[cfg(stage0)]
870893
impl fmt::Show for MutableSpace {

0 commit comments

Comments
 (0)