Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9dd6561

Browse files
committedFeb 15, 2025
use a HashSet instead of IndexSet for cache of types with notable trait impls
iteration order shouldn't matter
1 parent 673c42b commit 9dd6561

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
@@ -6,7 +6,7 @@ use std::path::{Path, PathBuf};
66
use std::sync::mpsc::{Receiver, channel};
77

88
use rinja::Template;
9-
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet};
9+
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
1010
use rustc_hir::def_id::{DefIdMap, LOCAL_CRATE};
1111
use rustc_middle::ty::TyCtxt;
1212
use rustc_session::Session;
@@ -62,7 +62,7 @@ pub(crate) struct Context<'tcx> {
6262
/// [#82381]: https://github.com/rust-lang/rust/issues/82381
6363
pub(crate) shared: SharedContext<'tcx>,
6464
/// Collection of all types with notable traits referenced in the current module.
65-
pub(crate) types_with_notable_traits: RefCell<FxIndexSet<clean::Type>>,
65+
pub(crate) types_with_notable_traits: RefCell<FxHashSet<clean::Type>>,
6666
/// Contains information that needs to be saved and reset after rendering an item which is
6767
/// not a module.
6868
pub(crate) info: ContextInfo,
@@ -587,7 +587,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
587587
id_map: RefCell::new(id_map),
588588
deref_id_map: Default::default(),
589589
shared: scx,
590-
types_with_notable_traits: RefCell::new(FxIndexSet::default()),
590+
types_with_notable_traits: RefCell::default(),
591591
info: ContextInfo::new(include_sources),
592592
};
593593

‎src/librustdoc/html/render/mod.rs

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

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

‎src/librustdoc/html/render/print_item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ pub(super) fn print_item(cx: &Context<'_>, item: &clean::Item, buf: &mut String)
284284
buf,
285285
format_args!(
286286
r#"<script type="text/json" id="notable-traits-data">{}</script>"#,
287-
notable_traits_json(types_with_notable_traits.iter(), cx)
287+
notable_traits_json(&types_with_notable_traits, cx)
288288
),
289289
);
290290
types_with_notable_traits.clear();

0 commit comments

Comments
 (0)
Failed to load comments.