Skip to content

Commit 1884983

Browse files
Make impl associated constants sorted first
1 parent f96aff9 commit 1884983

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

src/librustdoc/html/render/mod.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1796,24 +1796,24 @@ fn render_impl(
17961796

17971797
// Impl items are grouped by kinds:
17981798
//
1799-
// 1. Types
1800-
// 2. Constants
1799+
// 1. Constants
1800+
// 2. Types
18011801
// 3. Functions
18021802
//
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();
1803+
// This order is because you can have associated constants used in associated types (like array
1804+
// length), and both in associcated functions. So with this order, when reading from top to
1805+
// bottom, you should see items definitions before they're actually used most of the time.
1806+
let mut assoc_types = Vec::new();
18071807
let mut methods = Vec::new();
18081808

18091809
if !impl_.is_negative_trait_impl() {
18101810
for trait_item in &impl_.items {
18111811
match *trait_item.kind {
18121812
clean::MethodItem(..) | clean::TyMethodItem(_) => methods.push(trait_item),
1813-
clean::TyAssocConstItem(..) | clean::AssocConstItem(_) => {
1814-
assoc_consts.push(trait_item)
1815-
}
18161813
clean::TyAssocTypeItem(..) | clean::AssocTypeItem(..) => {
1814+
assoc_types.push(trait_item)
1815+
}
1816+
clean::TyAssocConstItem(..) | clean::AssocConstItem(_) => {
18171817
// We render it directly since they're supposed to come first.
18181818
doc_impl_item(
18191819
&mut default_impl_items,
@@ -1832,12 +1832,12 @@ fn render_impl(
18321832
}
18331833
}
18341834

1835-
for assoc_const in assoc_consts {
1835+
for assoc_type in assoc_types {
18361836
doc_impl_item(
18371837
&mut default_impl_items,
18381838
&mut impl_items,
18391839
cx,
1840-
assoc_const,
1840+
assoc_type,
18411841
if trait_.is_some() { &i.impl_item } else { parent },
18421842
link,
18431843
render_mode,

src/librustdoc/html/render/sidebar.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,10 +302,10 @@ fn sidebar_trait<'a>(
302302

303303
blocks.extend(
304304
[
305-
("required-associated-types", "Required Associated Types", req_assoc),
306-
("provided-associated-types", "Provided Associated Types", prov_assoc),
307305
("required-associated-consts", "Required Associated Constants", req_assoc_const),
308306
("provided-associated-consts", "Provided Associated Constants", prov_assoc_const),
307+
("required-associated-types", "Required Associated Types", req_assoc),
308+
("provided-associated-types", "Provided Associated Types", prov_assoc),
309309
("required-methods", "Required Methods", req_method),
310310
("provided-methods", "Provided Methods", prov_method),
311311
("foreign-impls", "Implementations on Foreign Types", foreign_impls),

tests/rustdoc/impl-associated-items-order.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// This test ensures that impl associated items always follow this order:
22
//
3-
// 1. Types
4-
// 2. Consts
3+
// 1. Consts
4+
// 2. Types
55
// 3. Functions
66

77
#![feature(inherent_associated_types)]
@@ -15,10 +15,10 @@ impl Bar {
1515
//@ has - '//*[@id="implementations-list"]//*[@class="impl-items"]/section[3]/h4' \
1616
// 'pub fn foo()'
1717
pub fn foo() {}
18-
//@ has - '//*[@id="implementations-list"]//*[@class="impl-items"]/section[2]/h4' \
18+
//@ has - '//*[@id="implementations-list"]//*[@class="impl-items"]/section[1]/h4' \
1919
// 'pub const X: u8 = 12u8'
2020
pub const X: u8 = 12;
21-
//@ has - '//*[@id="implementations-list"]//*[@class="impl-items"]/section[1]/h4' \
21+
//@ has - '//*[@id="implementations-list"]//*[@class="impl-items"]/section[2]/h4' \
2222
// 'pub type Y = u8'
2323
pub type Y = u8;
2424
}
@@ -31,11 +31,11 @@ pub trait Foo {
3131

3232
impl Foo for Bar {
3333
//@ has - '//*[@id="trait-implementations-list"]//*[@class="impl-items"]/section[2]/h4' \
34-
// 'const W: u32 = 12u32'
35-
const W: u32 = 12;
36-
//@ has - '//*[@id="trait-implementations-list"]//*[@class="impl-items"]/section[1]/h4' \
3734
// 'type Z = u8'
3835
type Z = u8;
36+
//@ has - '//*[@id="trait-implementations-list"]//*[@class="impl-items"]/section[1]/h4' \
37+
// 'const W: u32 = 12u32'
38+
const W: u32 = 12;
3939
//@ has - '//*[@id="trait-implementations-list"]//*[@class="impl-items"]/section[3]/h4' \
4040
// 'fn yeay()'
4141
fn yeay() {}

0 commit comments

Comments
 (0)