forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#129471 - GuillaumeGomez:sort-impl-associate…
…d-items, r=t-rustdoc-frontend [rustdoc] Sort impl associated items by kinds and then by appearance Following [this zulip discussion](https://rust-lang.zulipchat.com/#narrow/stream/266220-t-rustdoc/topic/.22Freeze.22.20order.20of.20items.20in.20.28trait.29.20impls.3F), I implemented it. This brings the following change: impl associated items will now be grouped by kind and will now be first sorted by kind and then by the order they are declared in the source code (like currently). The kinds are sorted in the following order: 1. Constants 2. Types 3. Functions The reason behind this order is that associated constants can be used in associated types (like length in arrays) and both associated types and associated constants can be used in associated functions. So if an associated item from the same impl is used, its definition will always be above where it's being used. cc `@camelid` r? `@notriddle`
- Loading branch information
Showing
5 changed files
with
182 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// This test ensures that impl associated items always follow this order: | ||
// | ||
// 1. Consts | ||
// 2. Types | ||
// 3. Functions | ||
|
||
#![feature(inherent_associated_types)] | ||
#![allow(incomplete_features)] | ||
#![crate_name = "foo"] | ||
|
||
//@ has 'foo/struct.Bar.html' | ||
pub struct Bar; | ||
|
||
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[1]/h4' \ | ||
// 'pub const X: u8 = 12u8' | ||
pub const X: u8 = 12; | ||
//@ has - '//*[@id="implementations-list"]//*[@class="impl-items"]/section[2]/h4' \ | ||
// 'pub type Y = u8' | ||
pub type Y = u8; | ||
} | ||
|
||
pub trait Foo { | ||
const W: u32; | ||
fn yeay(); | ||
type Z; | ||
} | ||
|
||
impl Foo for Bar { | ||
//@ has - '//*[@id="trait-implementations-list"]//*[@class="impl-items"]/section[2]/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() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// This test ensures that impl/trait associated items are listed in the sidebar. | ||
|
||
// ignore-tidy-linelength | ||
|
||
#![feature(inherent_associated_types)] | ||
#![feature(associated_type_defaults)] | ||
#![allow(incomplete_features)] | ||
#![crate_name = "foo"] | ||
|
||
//@ has 'foo/struct.Bar.html' | ||
pub struct Bar; | ||
|
||
impl Bar { | ||
//@ has - '//*[@class="sidebar-elems"]//h3[1]' 'Associated Constants' | ||
//@ has - '//*[@class="sidebar-elems"]//ul[@class="block associatedconstant"]/li/a[@href="#associatedconstant.X"]' 'X' | ||
pub const X: u8 = 12; | ||
//@ has - '//*[@class="sidebar-elems"]//h3[2]' 'Associated Types' | ||
//@ has - '//*[@class="sidebar-elems"]//ul[@class="block associatedtype"]/li/a[@href="#associatedtype.Y"]' 'Y' | ||
pub type Y = u8; | ||
} | ||
|
||
//@ has 'foo/trait.Foo.html' | ||
pub trait Foo { | ||
//@ has - '//*[@class="sidebar-elems"]//h3[5]' 'Required Methods' | ||
//@ has - '//*[@class="sidebar-elems"]//ul[@class="block"][5]/li/a[@href="#tymethod.yeay"]' 'yeay' | ||
fn yeay(); | ||
//@ has - '//*[@class="sidebar-elems"]//h3[6]' 'Provided Methods' | ||
//@ has - '//*[@class="sidebar-elems"]//ul[@class="block"][6]/li/a[@href="#method.boo"]' 'boo' | ||
fn boo() {} | ||
//@ has - '//*[@class="sidebar-elems"]//h3[1]' 'Required Associated Constants' | ||
//@ has - '//*[@class="sidebar-elems"]//ul[@class="block"][1]/li/a[@href="#associatedconstant.W"]' 'W' | ||
const W: u32; | ||
//@ has - '//*[@class="sidebar-elems"]//h3[2]' 'Provided Associated Constants' | ||
//@ has - '//*[@class="sidebar-elems"]//ul[@class="block"][2]/li/a[@href="#associatedconstant.U"]' 'U' | ||
const U: u32 = 0; | ||
//@ has - '//*[@class="sidebar-elems"]//h3[3]' 'Required Associated Types' | ||
//@ has - '//*[@class="sidebar-elems"]//ul[@class="block"][3]/li/a[@href="#associatedtype.Z"]' 'Z' | ||
type Z; | ||
//@ has - '//*[@class="sidebar-elems"]//h3[4]' 'Provided Associated Types' | ||
//@ has - '//*[@class="sidebar-elems"]//ul[@class="block"][4]/li/a[@href="#associatedtype.T"]' 'T' | ||
type T = u32; | ||
} |