Skip to content

Commit

Permalink
Rollup merge of rust-lang#120641 - klensy:copypaste-me, r=notriddle
Browse files Browse the repository at this point in the history
rustdoc: trait.impl, type.impl: sort impls to make it not depend on serialization order

Can be tested by running `cargo doc` with different rust versions on some crate and comparing `doc` folders: files in `trait.impl` and `type.impl` will sometimes have different order of impls.
  • Loading branch information
matthiaskrgr authored Feb 4, 2024
2 parents 4a16342 + cb4e69a commit 3e88221
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions src/librustdoc/html/render/write_shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -593,11 +593,17 @@ else if (window.initSearch) window.initSearch(searchIndex);
ret
})
.collect::<Vec<_>>();
let impls = format!(
r#""{}":{}"#,
krate.name(cx.tcx()),
serde_json::to_string(&impls).expect("failed serde conversion"),
);

// FIXME: this fixes only rustdoc part of instability of trait impls
// for js files, see #120371
// Manually collect to string and sort to make list not depend on order
let mut impls = impls
.iter()
.map(|i| serde_json::to_string(i).expect("failed serde conversion"))
.collect::<Vec<_>>();
impls.sort();

let impls = format!(r#""{}":[{}]"#, krate.name(cx.tcx()), impls.join(","));

let mut mydst = dst.clone();
for part in &aliased_type.target_fqp[..aliased_type.target_fqp.len() - 1] {
Expand Down Expand Up @@ -702,11 +708,16 @@ else if (window.initSearch) window.initSearch(searchIndex);
continue;
}

let implementors = format!(
r#""{}":{}"#,
krate.name(cx.tcx()),
serde_json::to_string(&implementors).expect("failed serde conversion"),
);
// FIXME: this fixes only rustdoc part of instability of trait impls
// for js files, see #120371
// Manually collect to string and sort to make list not depend on order
let mut implementors = implementors
.iter()
.map(|i| serde_json::to_string(i).expect("failed serde conversion"))
.collect::<Vec<_>>();
implementors.sort();

let implementors = format!(r#""{}":[{}]"#, krate.name(cx.tcx()), implementors.join(","));

let mut mydst = dst.clone();
for part in &remote_path[..remote_path.len() - 1] {
Expand Down

0 comments on commit 3e88221

Please sign in to comment.