Skip to content

Commit a40032d

Browse files
committed
Simplify notable traits map serialization
1 parent 82fecf0 commit a40032d

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};
@@ -60,8 +61,6 @@ use rustc_middle::ty::print::PrintTraitRefExt;
6061
use rustc_middle::ty::{self, TyCtxt};
6162
use rustc_span::symbol::{Symbol, sym};
6263
use rustc_span::{BytePos, DUMMY_SP, FileName, RealFileName};
63-
use serde::ser::SerializeMap;
64-
use serde::{Serialize, Serializer};
6564
use tracing::{debug, info};
6665

6766
pub(crate) use self::context::*;
@@ -1722,23 +1721,9 @@ fn notable_traits_decl(ty: &clean::Type, cx: &Context<'_>) -> (String, String) {
17221721
}
17231722

17241723
fn notable_traits_json<'a>(tys: impl Iterator<Item = &'a clean::Type>, cx: &Context<'_>) -> String {
1725-
let mut mp: Vec<(String, String)> = tys.map(|ty| notable_traits_decl(ty, cx)).collect();
1726-
mp.sort_by(|(name1, _html1), (name2, _html2)| name1.cmp(name2));
1727-
struct NotableTraitsMap(Vec<(String, String)>);
1728-
impl Serialize for NotableTraitsMap {
1729-
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1730-
where
1731-
S: Serializer,
1732-
{
1733-
let mut map = serializer.serialize_map(Some(self.0.len()))?;
1734-
for item in &self.0 {
1735-
map.serialize_entry(&item.0, &item.1)?;
1736-
}
1737-
map.end()
1738-
}
1739-
}
1740-
serde_json::to_string(&NotableTraitsMap(mp))
1741-
.expect("serialize (string, string) -> json object cannot fail")
1724+
let mut mp = tys.map(|ty| notable_traits_decl(ty, cx)).collect::<IndexMap<_, _>>();
1725+
mp.sort_unstable_keys();
1726+
serde_json::to_string(&mp).expect("serialize (string, string) -> json object cannot fail")
17421727
}
17431728

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

0 commit comments

Comments
 (0)