@@ -1784,13 +1784,64 @@ fn render_impl(
17841784 let mut default_impl_items = Buffer :: empty_from ( w) ;
17851785 let impl_ = i. inner_impl ( ) ;
17861786
1787+ // Impl items are grouped by kinds:
1788+ //
1789+ // 1. Types
1790+ // 2. Constants
1791+ // 3. Functions
1792+ //
1793+ // This order is because you can have associated types in associated constants, and both in
1794+ // associcated functions. So with this order, when reading from top to bottom, you should always
1795+ // see all items definitions before they're actually used.
1796+ let mut assoc_consts = Vec :: new ( ) ;
1797+ let mut methods = Vec :: new ( ) ;
1798+
17871799 if !impl_. is_negative_trait_impl ( ) {
17881800 for trait_item in & impl_. items {
1801+ match * trait_item. kind {
1802+ clean:: MethodItem ( ..) | clean:: TyMethodItem ( _) => methods. push ( trait_item) ,
1803+ clean:: TyAssocConstItem ( ..) | clean:: AssocConstItem ( _) => {
1804+ assoc_consts. push ( trait_item)
1805+ }
1806+ clean:: TyAssocTypeItem ( ..) | clean:: AssocTypeItem ( ..) => {
1807+ // We render it directly since they're supposed to come first.
1808+ doc_impl_item (
1809+ & mut default_impl_items,
1810+ & mut impl_items,
1811+ cx,
1812+ trait_item,
1813+ if trait_. is_some ( ) { & i. impl_item } else { parent } ,
1814+ link,
1815+ render_mode,
1816+ false ,
1817+ trait_,
1818+ rendering_params,
1819+ ) ;
1820+ }
1821+ _ => { }
1822+ }
1823+ }
1824+
1825+ for assoc_const in assoc_consts {
17891826 doc_impl_item (
17901827 & mut default_impl_items,
17911828 & mut impl_items,
17921829 cx,
1793- trait_item,
1830+ assoc_const,
1831+ if trait_. is_some ( ) { & i. impl_item } else { parent } ,
1832+ link,
1833+ render_mode,
1834+ false ,
1835+ trait_,
1836+ rendering_params,
1837+ ) ;
1838+ }
1839+ for method in methods {
1840+ doc_impl_item (
1841+ & mut default_impl_items,
1842+ & mut impl_items,
1843+ cx,
1844+ method,
17941845 if trait_. is_some ( ) { & i. impl_item } else { parent } ,
17951846 link,
17961847 render_mode,
0 commit comments