Skip to content

Commit afdf48d

Browse files
committed
use a HashSet instead of IndexSet for cache of types with notable trait impls
iteration order shouldn't matter
1 parent ce49774 commit afdf48d

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

src/librustdoc/html/render/context.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::path::{Path, PathBuf};
55
use std::sync::mpsc::{Receiver, channel};
66

77
use rinja::Template;
8-
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet};
8+
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
99
use rustc_hir::def_id::{DefIdMap, LOCAL_CRATE};
1010
use rustc_middle::ty::TyCtxt;
1111
use rustc_session::Session;
@@ -60,7 +60,7 @@ pub(crate) struct Context<'tcx> {
6060
/// [#82381]: https://github.com/rust-lang/rust/issues/82381
6161
pub(crate) shared: SharedContext<'tcx>,
6262
/// Collection of all types with notable traits referenced in the current module.
63-
pub(crate) types_with_notable_traits: RefCell<FxIndexSet<clean::Type>>,
63+
pub(crate) types_with_notable_traits: RefCell<FxHashSet<clean::Type>>,
6464
/// Contains information that needs to be saved and reset after rendering an item which is
6565
/// not a module.
6666
pub(crate) info: ContextInfo,
@@ -579,7 +579,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
579579
id_map: RefCell::new(id_map),
580580
deref_id_map: Default::default(),
581581
shared: scx,
582-
types_with_notable_traits: RefCell::new(FxIndexSet::default()),
582+
types_with_notable_traits: RefCell::default(),
583583
info: ContextInfo::new(include_sources),
584584
};
585585

src/librustdoc/html/render/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1545,10 +1545,10 @@ fn notable_traits_decl(ty: &clean::Type, cx: &Context<'_>) -> (String, String) {
15451545
(format!("{:#}", ty.print(cx)), out.into_inner())
15461546
}
15471547

1548-
pub(crate) fn notable_traits_json<'a>(
1549-
tys: impl Iterator<Item = &'a clean::Type>,
1550-
cx: &Context<'_>,
1551-
) -> String {
1548+
pub(crate) fn notable_traits_json(tys: &FxHashSet<clean::Type>, cx: &Context<'_>) -> String {
1549+
#[expect(rustc::potential_query_instability, reason = "items are sorted by name")]
1550+
let tys = tys.iter();
1551+
15521552
let mut mp: Vec<(String, String)> = tys.map(|ty| notable_traits_decl(ty, cx)).collect();
15531553
mp.sort_by(|(name1, _html1), (name2, _html2)| name1.cmp(name2));
15541554
struct NotableTraitsMap(Vec<(String, String)>);

src/librustdoc/html/render/print_item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ pub(super) fn print_item(cx: &Context<'_>, item: &clean::Item, buf: &mut Buffer)
281281
write!(
282282
buf,
283283
r#"<script type="text/json" id="notable-traits-data">{}</script>"#,
284-
notable_traits_json(types_with_notable_traits.iter(), cx)
284+
notable_traits_json(&types_with_notable_traits, cx)
285285
);
286286
types_with_notable_traits.clear();
287287
}

0 commit comments

Comments
 (0)