Skip to content

Commit a459403

Browse files
Sort impl associated items by kinds and then by appearance
1 parent eb33b43 commit a459403

File tree

1 file changed

+52
-1
lines changed
  • src/librustdoc/html/render

1 file changed

+52
-1
lines changed

src/librustdoc/html/render/mod.rs

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1794,13 +1794,64 @@ fn render_impl(
17941794
let mut default_impl_items = Buffer::empty_from(w);
17951795
let impl_ = i.inner_impl();
17961796

1797+
// Impl items are grouped by kinds:
1798+
//
1799+
// 1. Types
1800+
// 2. Constants
1801+
// 3. Functions
1802+
//
1803+
// This order is because you can have associated types in associated constants, and both in
1804+
// associcated functions. So with this order, when reading from top to bottom, you should always
1805+
// see all items definitions before they're actually used.
1806+
let mut assoc_consts = Vec::new();
1807+
let mut methods = Vec::new();
1808+
17971809
if !impl_.is_negative_trait_impl() {
17981810
for trait_item in &impl_.items {
1811+
match *trait_item.kind {
1812+
clean::MethodItem(..) | clean::TyMethodItem(_) => methods.push(trait_item),
1813+
clean::TyAssocConstItem(..) | clean::AssocConstItem(_) => {
1814+
assoc_consts.push(trait_item)
1815+
}
1816+
clean::TyAssocTypeItem(..) | clean::AssocTypeItem(..) => {
1817+
// We render it directly since they're supposed to come first.
1818+
doc_impl_item(
1819+
&mut default_impl_items,
1820+
&mut impl_items,
1821+
cx,
1822+
trait_item,
1823+
if trait_.is_some() { &i.impl_item } else { parent },
1824+
link,
1825+
render_mode,
1826+
false,
1827+
trait_,
1828+
rendering_params,
1829+
);
1830+
}
1831+
_ => {}
1832+
}
1833+
}
1834+
1835+
for assoc_const in assoc_consts {
17991836
doc_impl_item(
18001837
&mut default_impl_items,
18011838
&mut impl_items,
18021839
cx,
1803-
trait_item,
1840+
assoc_const,
1841+
if trait_.is_some() { &i.impl_item } else { parent },
1842+
link,
1843+
render_mode,
1844+
false,
1845+
trait_,
1846+
rendering_params,
1847+
);
1848+
}
1849+
for method in methods {
1850+
doc_impl_item(
1851+
&mut default_impl_items,
1852+
&mut impl_items,
1853+
cx,
1854+
method,
18041855
if trait_.is_some() { &i.impl_item } else { parent },
18051856
link,
18061857
render_mode,

0 commit comments

Comments
 (0)