Skip to content

Commit 489b792

Browse files
committed
Auto merge of #43515 - QuietMisdreavus:show-assoc-types, r=GuillaumeGomez
rustdoc: print associated types in traits "implementors" section When viewing a trait's implementors, they won't show anything about the implementation other than any bounds on the generics. You can see the full implementation details on the page for the type, but if the type is external (e.g. it's an extension trait being implemented for primitives), then you'll never be able to see the details of the implementation without opening the source code. This doesn't solve everything about that, but it does still show an incredibly useful piece of information: the associated types. This can help immensely for traits like `Deref` or `IntoIterator` in libstd, and also for traits like `IntoFuture` outside the standard library. Fixes #24200 🚨 BIKESHED ALERT 🚨 The indentation and sizing of the types is suspect. I put it in the small text so it wouldn't blend in with the next impl line. (It shares a CSS class with the where clauses, as you can see in the following image.) However, the indentation is nonstandard. I initially tried with no indentation (looked awkward and blended too well with the surrounding impls) and with 4-space indentation (too easy to confuse with where clauses), before settling on the 2-space indentation seen below. It's... okay, i guess. Open to suggestions. ![snippet of the implementors of IntoIterator, showing the associated types](https://user-images.githubusercontent.com/5217170/28697456-a4e01a12-7301-11e7-868e-2a6441d6c9e0.png)
2 parents 477e9f0 + 612081a commit 489b792

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

Diff for: src/librustdoc/html/render.rs

+7
Original file line numberDiff line numberDiff line change
@@ -2235,6 +2235,13 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
22352235
_ => false,
22362236
};
22372237
fmt_impl_for_trait_page(&implementor.impl_, w, use_absolute)?;
2238+
for it in &implementor.impl_.items {
2239+
if let clean::TypedefItem(ref tydef, _) = it.inner {
2240+
write!(w, "<span class=\"where fmt-newline\"> ")?;
2241+
assoc_type(w, it, &vec![], Some(&tydef.type_), AssocItemLink::Anchor(None))?;
2242+
write!(w, ";</span>")?;
2243+
}
2244+
}
22382245
writeln!(w, "</code></li>")?;
22392246
}
22402247
}

0 commit comments

Comments
 (0)