Skip to content

Commit b20f40d

Browse files
committed
Auto merge of #117521 - GuillaumeGomez:impl-on-foreign-order, r=notriddle
Fix order of implementations in the "implementations on foreign types" section Fixes #117391. We forgot to run the `sort_by_cached_key` on this section. This fixes it. r? `@notriddle`
2 parents c5afe0a + 2e4a36b commit b20f40d

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

src/librustdoc/html/render/print_item.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -991,14 +991,15 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
991991
}
992992
}
993993

994-
let (local, foreign) =
994+
let (local, mut foreign) =
995995
implementors.iter().partition::<Vec<_>, _>(|i| i.is_on_local_type(cx));
996996

997997
let (mut synthetic, mut concrete): (Vec<&&Impl>, Vec<&&Impl>) =
998998
local.iter().partition(|i| i.inner_impl().kind.is_auto());
999999

10001000
synthetic.sort_by_cached_key(|i| ImplString::new(i, cx));
10011001
concrete.sort_by_cached_key(|i| ImplString::new(i, cx));
1002+
foreign.sort_by_cached_key(|i| ImplString::new(i, cx));
10021003

10031004
if !foreign.is_empty() {
10041005
write_small_section_header(w, "foreign-impls", "Implementations on Foreign Types", "");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// This test ensures that the "implementations on foreign types" of a trait are correctly sorted.
2+
go-to: "file://" + |DOC_PATH| + "/test_docs/foreign_impl_order/trait.Foo.html"
3+
assert-text: ("details:nth-of-type(1) h3", "impl Foo<1> for [u8; 1]")
4+
assert-text: ("details:nth-of-type(2) h3", "impl Foo<2> for [u8; 2]")
5+
assert-text: ("details:nth-of-type(3) h3", "impl Foo<3> for [u8; 3]")
6+
assert-text: ("details:nth-of-type(4) h3", "impl Foo<4> for [u8; 4]")

tests/rustdoc-gui/search-tab.goml

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ call-function: ("check-colors", {
7979
set-window-size: (851, 600)
8080

8181
// Check the size and count in tabs
82-
assert-text: ("#search-tabs > button:nth-child(1) > .count", " (24) ")
82+
assert-text: ("#search-tabs > button:nth-child(1) > .count", " (25) ")
8383
assert-text: ("#search-tabs > button:nth-child(2) > .count", " (5)  ")
8484
assert-text: ("#search-tabs > button:nth-child(3) > .count", " (0)  ")
8585
store-property: ("#search-tabs > button:nth-child(1)", {"offsetWidth": buttonWidth})

tests/rustdoc-gui/src/test_docs/lib.rs

+19
Original file line numberDiff line numberDiff line change
@@ -574,3 +574,22 @@ impl ZyxwvutTrait for ZyxwvutMethodDisambiguation {
574574
x
575575
}
576576
}
577+
578+
pub mod foreign_impl_order {
579+
pub trait Foo<const W: usize> {
580+
fn f(&mut self, with: [u8; W]);
581+
}
582+
583+
impl Foo<4> for [u8; 4] {
584+
fn f(&mut self, fg: [u8; 4]) {}
585+
}
586+
impl Foo<2> for [u8; 2] {
587+
fn f(&mut self, fg: [u8; 2]) {}
588+
}
589+
impl Foo<1> for [u8; 1] {
590+
fn f(&mut self, fg: [u8; 1]) {}
591+
}
592+
impl Foo<3> for [u8; 3] {
593+
fn f(&mut self, fg: [u8; 3]) {}
594+
}
595+
}

0 commit comments

Comments
 (0)