Skip to content

Commit 071acdf

Browse files
authored
Rollup merge of rust-lang#67152 - GuillaumeGomez:sort-auto-impls, r=kinnison
Sort auto trait and blanket implementations display Fixes rust-lang#63042 r? @kinnison
2 parents a7f9307 + 9e3e421 commit 071acdf

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

src/librustdoc/html/format.rs

+11
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ impl Buffer {
6363
}
6464
}
6565

66+
crate fn new() -> Buffer {
67+
Buffer {
68+
for_html: false,
69+
buffer: String::new(),
70+
}
71+
}
72+
6673
crate fn is_empty(&self) -> bool {
6774
self.buffer.is_empty()
6875
}
@@ -106,6 +113,10 @@ impl Buffer {
106113
write!(self, "{:#}", t);
107114
}
108115
}
116+
117+
crate fn is_for_html(&self) -> bool {
118+
self.for_html
119+
}
109120
}
110121

111122
/// Wrapper struct for properly emitting a function or method declaration.

src/librustdoc/html/render.rs

+17-6
Original file line numberDiff line numberDiff line change
@@ -2282,12 +2282,23 @@ fn render_implementor(cx: &Context, implementor: &Impl, w: &mut Buffer,
22822282
fn render_impls(cx: &Context, w: &mut Buffer,
22832283
traits: &[&&Impl],
22842284
containing_item: &clean::Item) {
2285-
for i in traits {
2286-
let did = i.trait_did().unwrap();
2287-
let assoc_link = AssocItemLink::GotoSource(did, &i.inner_impl().provided_trait_methods);
2288-
render_impl(w, cx, i, assoc_link,
2289-
RenderMode::Normal, containing_item.stable_since(), true, None, false, true);
2290-
}
2285+
let mut impls = traits.iter()
2286+
.map(|i| {
2287+
let did = i.trait_did().unwrap();
2288+
let assoc_link = AssocItemLink::GotoSource(did, &i.inner_impl().provided_trait_methods);
2289+
let mut buffer = if w.is_for_html() {
2290+
Buffer::html()
2291+
} else {
2292+
Buffer::new()
2293+
};
2294+
render_impl(&mut buffer, cx, i, assoc_link,
2295+
RenderMode::Normal, containing_item.stable_since(),
2296+
true, None, false, true);
2297+
buffer.into_inner()
2298+
})
2299+
.collect::<Vec<_>>();
2300+
impls.sort();
2301+
w.write_str(&impls.join(""));
22912302
}
22922303

22932304
fn bounds(t_bounds: &[clean::GenericBound], trait_alias: bool) -> String {

0 commit comments

Comments
 (0)