Skip to content

Commit 8f2e717

Browse files
committed
Simplify notable traits map serialization
1 parent 50b01d5 commit 8f2e717

File tree

2 files changed

+5
-20
lines changed

2 files changed

+5
-20
lines changed

src/librustdoc/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ path = "lib.rs"
1212
arrayvec = { version = "0.7", default-features = false }
1313
askama = { version = "0.14", default-features = false, features = ["alloc", "config", "derive"] }
1414
base64 = "0.21.7"
15-
indexmap = "2"
15+
indexmap = { version = "2", features = ["serde"] }
1616
itertools = "0.12"
1717
minifier = { version = "0.3.5", default-features = false }
1818
pulldown-cmark-escape = { version = "0.11.0", features = ["simd"] }

src/librustdoc/html/render/mod.rs

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ use std::path::PathBuf;
4848
use std::{fs, str};
4949

5050
use askama::Template;
51+
use indexmap::IndexMap;
5152
use itertools::Either;
5253
use rustc_ast::join_path_syms;
5354
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
@@ -58,8 +59,6 @@ use rustc_middle::ty::print::PrintTraitRefExt;
5859
use rustc_middle::ty::{self, TyCtxt};
5960
use rustc_span::symbol::{Symbol, sym};
6061
use rustc_span::{BytePos, DUMMY_SP, FileName, RealFileName};
61-
use serde::ser::SerializeMap;
62-
use serde::{Serialize, Serializer};
6362
use tracing::{debug, info};
6463

6564
pub(crate) use self::context::*;
@@ -1757,23 +1756,9 @@ fn notable_traits_decl(ty: &clean::Type, cx: &Context<'_>) -> (String, String) {
17571756
}
17581757

17591758
fn notable_traits_json<'a>(tys: impl Iterator<Item = &'a clean::Type>, cx: &Context<'_>) -> String {
1760-
let mut mp: Vec<(String, String)> = tys.map(|ty| notable_traits_decl(ty, cx)).collect();
1761-
mp.sort_by(|(name1, _html1), (name2, _html2)| name1.cmp(name2));
1762-
struct NotableTraitsMap(Vec<(String, String)>);
1763-
impl Serialize for NotableTraitsMap {
1764-
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1765-
where
1766-
S: Serializer,
1767-
{
1768-
let mut map = serializer.serialize_map(Some(self.0.len()))?;
1769-
for item in &self.0 {
1770-
map.serialize_entry(&item.0, &item.1)?;
1771-
}
1772-
map.end()
1773-
}
1774-
}
1775-
serde_json::to_string(&NotableTraitsMap(mp))
1776-
.expect("serialize (string, string) -> json object cannot fail")
1759+
let mut mp = tys.map(|ty| notable_traits_decl(ty, cx)).collect::<IndexMap<_, _>>();
1760+
mp.sort_unstable_keys();
1761+
serde_json::to_string(&mp).expect("serialize (string, string) -> json object cannot fail")
17771762
}
17781763

17791764
#[derive(Clone, Copy, Debug)]

0 commit comments

Comments
 (0)