@@ -1794,13 +1794,64 @@ fn render_impl(
1794
1794
let mut default_impl_items = Buffer :: empty_from ( w) ;
1795
1795
let impl_ = i. inner_impl ( ) ;
1796
1796
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
+
1797
1809
if !impl_. is_negative_trait_impl ( ) {
1798
1810
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 {
1799
1836
doc_impl_item (
1800
1837
& mut default_impl_items,
1801
1838
& mut impl_items,
1802
1839
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,
1804
1855
if trait_. is_some ( ) { & i. impl_item } else { parent } ,
1805
1856
link,
1806
1857
render_mode,
0 commit comments