Make impl associated constants sorted first
This commit is contained in:
parent
f96aff95d5
commit
1884983001
@ -1796,24 +1796,24 @@ fn doc_impl_item(
|
|||||||
|
|
||||||
// Impl items are grouped by kinds:
|
// Impl items are grouped by kinds:
|
||||||
//
|
//
|
||||||
// 1. Types
|
// 1. Constants
|
||||||
// 2. Constants
|
// 2. Types
|
||||||
// 3. Functions
|
// 3. Functions
|
||||||
//
|
//
|
||||||
// This order is because you can have associated types in associated constants, and both in
|
// This order is because you can have associated constants used in associated types (like array
|
||||||
// associcated functions. So with this order, when reading from top to bottom, you should always
|
// length), and both in associcated functions. So with this order, when reading from top to
|
||||||
// see all items definitions before they're actually used.
|
// bottom, you should see items definitions before they're actually used most of the time.
|
||||||
let mut assoc_consts = Vec::new();
|
let mut assoc_types = Vec::new();
|
||||||
let mut methods = Vec::new();
|
let mut methods = Vec::new();
|
||||||
|
|
||||||
if !impl_.is_negative_trait_impl() {
|
if !impl_.is_negative_trait_impl() {
|
||||||
for trait_item in &impl_.items {
|
for trait_item in &impl_.items {
|
||||||
match *trait_item.kind {
|
match *trait_item.kind {
|
||||||
clean::MethodItem(..) | clean::TyMethodItem(_) => methods.push(trait_item),
|
clean::MethodItem(..) | clean::TyMethodItem(_) => methods.push(trait_item),
|
||||||
clean::TyAssocConstItem(..) | clean::AssocConstItem(_) => {
|
|
||||||
assoc_consts.push(trait_item)
|
|
||||||
}
|
|
||||||
clean::TyAssocTypeItem(..) | clean::AssocTypeItem(..) => {
|
clean::TyAssocTypeItem(..) | clean::AssocTypeItem(..) => {
|
||||||
|
assoc_types.push(trait_item)
|
||||||
|
}
|
||||||
|
clean::TyAssocConstItem(..) | clean::AssocConstItem(_) => {
|
||||||
// We render it directly since they're supposed to come first.
|
// We render it directly since they're supposed to come first.
|
||||||
doc_impl_item(
|
doc_impl_item(
|
||||||
&mut default_impl_items,
|
&mut default_impl_items,
|
||||||
@ -1832,12 +1832,12 @@ fn doc_impl_item(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for assoc_const in assoc_consts {
|
for assoc_type in assoc_types {
|
||||||
doc_impl_item(
|
doc_impl_item(
|
||||||
&mut default_impl_items,
|
&mut default_impl_items,
|
||||||
&mut impl_items,
|
&mut impl_items,
|
||||||
cx,
|
cx,
|
||||||
assoc_const,
|
assoc_type,
|
||||||
if trait_.is_some() { &i.impl_item } else { parent },
|
if trait_.is_some() { &i.impl_item } else { parent },
|
||||||
link,
|
link,
|
||||||
render_mode,
|
render_mode,
|
||||||
|
@ -302,10 +302,10 @@ fn filter_items<'a>(
|
|||||||
|
|
||||||
blocks.extend(
|
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),
|
("required-associated-consts", "Required Associated Constants", req_assoc_const),
|
||||||
("provided-associated-consts", "Provided Associated Constants", prov_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),
|
("required-methods", "Required Methods", req_method),
|
||||||
("provided-methods", "Provided Methods", prov_method),
|
("provided-methods", "Provided Methods", prov_method),
|
||||||
("foreign-impls", "Implementations on Foreign Types", foreign_impls),
|
("foreign-impls", "Implementations on Foreign Types", foreign_impls),
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// This test ensures that impl associated items always follow this order:
|
// This test ensures that impl associated items always follow this order:
|
||||||
//
|
//
|
||||||
// 1. Types
|
// 1. Consts
|
||||||
// 2. Consts
|
// 2. Types
|
||||||
// 3. Functions
|
// 3. Functions
|
||||||
|
|
||||||
#![feature(inherent_associated_types)]
|
#![feature(inherent_associated_types)]
|
||||||
@ -15,10 +15,10 @@ impl Bar {
|
|||||||
//@ has - '//*[@id="implementations-list"]//*[@class="impl-items"]/section[3]/h4' \
|
//@ has - '//*[@id="implementations-list"]//*[@class="impl-items"]/section[3]/h4' \
|
||||||
// 'pub fn foo()'
|
// 'pub fn foo()'
|
||||||
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 = 12u8'
|
||||||
pub const X: u8 = 12;
|
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'
|
||||||
pub type Y = u8;
|
pub type Y = u8;
|
||||||
}
|
}
|
||||||
@ -31,11 +31,11 @@ pub trait Foo {
|
|||||||
|
|
||||||
impl Foo for Bar {
|
impl Foo for Bar {
|
||||||
//@ has - '//*[@id="trait-implementations-list"]//*[@class="impl-items"]/section[2]/h4' \
|
//@ 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'
|
||||||
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' \
|
//@ has - '//*[@id="trait-implementations-list"]//*[@class="impl-items"]/section[3]/h4' \
|
||||||
// 'fn yeay()'
|
// 'fn yeay()'
|
||||||
fn yeay() {}
|
fn yeay() {}
|
||||||
|
Loading…
Reference in New Issue
Block a user