Skip to content

Commit 9017f79

Browse files
committed
Generate a page for existential types
1 parent 442d5d8 commit 9017f79

File tree

1 file changed

+37
-4
lines changed

1 file changed

+37
-4
lines changed

src/librustdoc/html/render.rs

+37-4
Original file line numberDiff line numberDiff line change
@@ -2103,6 +2103,7 @@ impl<'a> fmt::Display for Item<'a> {
21032103
clean::ConstantItem(..) => write!(fmt, "Constant ")?,
21042104
clean::ForeignTypeItem => write!(fmt, "Foreign Type ")?,
21052105
clean::KeywordItem(..) => write!(fmt, "Keyword ")?,
2106+
clean::ExistentialItem(..) => write!(fmt, "Existential Type ")?,
21062107
_ => {
21072108
// We don't generate pages for any other type.
21082109
unreachable!();
@@ -2167,6 +2168,7 @@ impl<'a> fmt::Display for Item<'a> {
21672168
clean::ConstantItem(ref c) => item_constant(fmt, self.cx, self.item, c),
21682169
clean::ForeignTypeItem => item_foreign_type(fmt, self.cx, self.item),
21692170
clean::KeywordItem(ref k) => item_keyword(fmt, self.cx, self.item, k),
2171+
clean::ExistentialItem(ref e, _) => item_existential(fmt, self.cx, self.item, e),
21702172
_ => {
21712173
// We don't generate pages for any other type.
21722174
unreachable!();
@@ -2685,18 +2687,17 @@ fn render_impls(cx: &Context, w: &mut fmt::Formatter,
26852687
Ok(())
26862688
}
26872689

2688-
fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
2689-
t: &clean::Trait) -> fmt::Result {
2690+
fn bounds(t_bounds: &[clean::GenericBound]) -> String {
26902691
let mut bounds = String::new();
26912692
let mut bounds_plain = String::new();
2692-
if !t.bounds.is_empty() {
2693+
if !t_bounds.is_empty() {
26932694
if !bounds.is_empty() {
26942695
bounds.push(' ');
26952696
bounds_plain.push(' ');
26962697
}
26972698
bounds.push_str(": ");
26982699
bounds_plain.push_str(": ");
2699-
for (i, p) in t.bounds.iter().enumerate() {
2700+
for (i, p) in t_bounds.iter().enumerate() {
27002701
if i > 0 {
27012702
bounds.push_str(" + ");
27022703
bounds_plain.push_str(" + ");
@@ -2705,7 +2706,16 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
27052706
bounds_plain.push_str(&format!("{:#}", *p));
27062707
}
27072708
}
2709+
bounds
2710+
}
27082711

2712+
fn item_trait(
2713+
w: &mut fmt::Formatter,
2714+
cx: &Context,
2715+
it: &clean::Item,
2716+
t: &clean::Trait,
2717+
) -> fmt::Result {
2718+
let bounds = bounds(&t.bounds);
27092719
let types = t.items.iter().filter(|m| m.is_associated_type()).collect::<Vec<_>>();
27102720
let consts = t.items.iter().filter(|m| m.is_associated_const()).collect::<Vec<_>>();
27112721
let required = t.items.iter().filter(|m| m.is_ty_method()).collect::<Vec<_>>();
@@ -3905,6 +3915,29 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
39053915
Ok(())
39063916
}
39073917

3918+
fn item_existential(
3919+
w: &mut fmt::Formatter,
3920+
cx: &Context,
3921+
it: &clean::Item,
3922+
t: &clean::Existential,
3923+
) -> fmt::Result {
3924+
write!(w, "<pre class='rust existential'>")?;
3925+
render_attributes(w, it)?;
3926+
write!(w, "existential type {}{}{where_clause}: {bounds};</pre>",
3927+
it.name.as_ref().unwrap(),
3928+
t.generics,
3929+
where_clause = WhereClause { gens: &t.generics, indent: 0, end_newline: true },
3930+
bounds = bounds(&t.bounds))?;
3931+
3932+
document(w, cx, it)?;
3933+
3934+
// Render any items associated directly to this alias, as otherwise they
3935+
// won't be visible anywhere in the docs. It would be nice to also show
3936+
// associated items from the aliased type (see discussion in #32077), but
3937+
// we need #14072 to make sense of the generics.
3938+
render_assoc_items(w, cx, it, it.def_id, AssocItemRender::All)
3939+
}
3940+
39083941
fn item_typedef(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
39093942
t: &clean::Typedef) -> fmt::Result {
39103943
write!(w, "<pre class='rust typedef'>")?;

0 commit comments

Comments
 (0)