diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs
index 9e993499276..095bfe158ff 100644
--- a/src/librustdoc/html/render/mod.rs
+++ b/src/librustdoc/html/render/mod.rs
@@ -1796,24 +1796,24 @@ fn render_impl(
// Impl items are grouped by kinds:
//
- // 1. Types
- // 2. Constants
+ // 1. Constants
+ // 2. Types
// 3. Functions
//
- // This order is because you can have associated types in associated constants, and both in
- // associcated functions. So with this order, when reading from top to bottom, you should always
- // see all items definitions before they're actually used.
- let mut assoc_consts = Vec::new();
+ // This order is because you can have associated constants used in associated types (like array
+ // length), and both in associcated functions. So with this order, when reading from top to
+ // bottom, you should see items definitions before they're actually used most of the time.
+ let mut assoc_types = Vec::new();
let mut methods = Vec::new();
if !impl_.is_negative_trait_impl() {
for trait_item in &impl_.items {
match *trait_item.kind {
clean::MethodItem(..) | clean::TyMethodItem(_) => methods.push(trait_item),
- clean::TyAssocConstItem(..) | clean::AssocConstItem(_) => {
- assoc_consts.push(trait_item)
- }
clean::TyAssocTypeItem(..) | clean::AssocTypeItem(..) => {
+ assoc_types.push(trait_item)
+ }
+ clean::TyAssocConstItem(..) | clean::AssocConstItem(_) => {
// We render it directly since they're supposed to come first.
doc_impl_item(
&mut default_impl_items,
@@ -1832,12 +1832,12 @@ fn render_impl(
}
}
- for assoc_const in assoc_consts {
+ for assoc_type in assoc_types {
doc_impl_item(
&mut default_impl_items,
&mut impl_items,
cx,
- assoc_const,
+ assoc_type,
if trait_.is_some() { &i.impl_item } else { parent },
link,
render_mode,
diff --git a/src/librustdoc/html/render/sidebar.rs b/src/librustdoc/html/render/sidebar.rs
index c75c28ef0a3..6d034504270 100644
--- a/src/librustdoc/html/render/sidebar.rs
+++ b/src/librustdoc/html/render/sidebar.rs
@@ -302,10 +302,10 @@ fn sidebar_trait<'a>(
blocks.extend(
[
- ("required-associated-types", "Required Associated Types", req_assoc),
- ("provided-associated-types", "Provided Associated Types", prov_assoc),
("required-associated-consts", "Required Associated Constants", req_assoc_const),
("provided-associated-consts", "Provided Associated Constants", prov_assoc_const),
+ ("required-associated-types", "Required Associated Types", req_assoc),
+ ("provided-associated-types", "Provided Associated Types", prov_assoc),
("required-methods", "Required Methods", req_method),
("provided-methods", "Provided Methods", prov_method),
("foreign-impls", "Implementations on Foreign Types", foreign_impls),
diff --git a/tests/rustdoc/impl-associated-items-order.rs b/tests/rustdoc/impl-associated-items-order.rs
index f8744be04ba..759e0f0b400 100644
--- a/tests/rustdoc/impl-associated-items-order.rs
+++ b/tests/rustdoc/impl-associated-items-order.rs
@@ -1,7 +1,7 @@
// This test ensures that impl associated items always follow this order:
//
-// 1. Types
-// 2. Consts
+// 1. Consts
+// 2. Types
// 3. Functions
#![feature(inherent_associated_types)]
@@ -15,10 +15,10 @@ impl Bar {
//@ has - '//*[@id="implementations-list"]//*[@class="impl-items"]/section[3]/h4' \
// 'pub fn foo()'
pub fn foo() {}
- //@ has - '//*[@id="implementations-list"]//*[@class="impl-items"]/section[2]/h4' \
+ //@ has - '//*[@id="implementations-list"]//*[@class="impl-items"]/section[1]/h4' \
// 'pub const X: u8 = 12u8'
pub const X: u8 = 12;
- //@ has - '//*[@id="implementations-list"]//*[@class="impl-items"]/section[1]/h4' \
+ //@ has - '//*[@id="implementations-list"]//*[@class="impl-items"]/section[2]/h4' \
// 'pub type Y = u8'
pub type Y = u8;
}
@@ -31,11 +31,11 @@ pub trait Foo {
impl Foo for Bar {
//@ has - '//*[@id="trait-implementations-list"]//*[@class="impl-items"]/section[2]/h4' \
- // 'const W: u32 = 12u32'
- const W: u32 = 12;
- //@ has - '//*[@id="trait-implementations-list"]//*[@class="impl-items"]/section[1]/h4' \
// 'type Z = u8'
type Z = u8;
+ //@ has - '//*[@id="trait-implementations-list"]//*[@class="impl-items"]/section[1]/h4' \
+ // 'const W: u32 = 12u32'
+ const W: u32 = 12;
//@ has - '//*[@id="trait-implementations-list"]//*[@class="impl-items"]/section[3]/h4' \
// 'fn yeay()'
fn yeay() {}