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 bca6fc2

Browse files
committedOct 4, 2024·
Auto merge of rust-lang#131259 - ismailarilik:handle-potential-query-instability-lint-for-librustdoc, r=<try>
Handle `librustdoc` cases of `rustc::potential_query_instability` lint This PR removes `#![allow(rustc::potential_query_instability)]` line from [`src/librustdoc/lib.rs`](https://github.com/rust-lang/rust/blob/master/src/librustdoc/lib.rs#L23) and converts `FxHash{Map,Set}` types into `FxIndex{Map,Set}` to suppress lint errors. A somewhat tracking issue: rust-lang#84447 r? `@compiler-errors`
2 parents c39f318 + 74187bd commit bca6fc2

23 files changed

+113
-114
lines changed
 

‎compiler/rustc_resolve/src/rustdoc.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use pulldown_cmark::{
66
};
77
use rustc_ast as ast;
88
use rustc_ast::util::comments::beautify_doc_string;
9-
use rustc_data_structures::fx::FxHashMap;
9+
use rustc_data_structures::fx::FxIndexMap;
1010
use rustc_middle::ty::TyCtxt;
1111
use rustc_span::def_id::DefId;
1212
use rustc_span::symbol::{Symbol, kw, sym};
@@ -235,8 +235,8 @@ fn span_for_value(attr: &ast::Attribute) -> Span {
235235
/// early and late doc link resolution regardless of their position.
236236
pub fn prepare_to_doc_link_resolution(
237237
doc_fragments: &[DocFragment],
238-
) -> FxHashMap<Option<DefId>, String> {
239-
let mut res = FxHashMap::default();
238+
) -> FxIndexMap<Option<DefId>, String> {
239+
let mut res = FxIndexMap::default();
240240
for fragment in doc_fragments {
241241
let out_str = res.entry(fragment.item_id).or_default();
242242
add_doc_fragment(out_str, fragment);

‎src/librustdoc/clean/types.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_ast::NestedMetaItem;
99
use rustc_ast_pretty::pprust;
1010
use rustc_attr::{ConstStability, Deprecation, Stability, StableSince};
1111
use rustc_const_eval::const_eval::is_unstable_const_fn;
12-
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
12+
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
1313
use rustc_hir::def::{CtorKind, DefKind, Res};
1414
use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE, LocalDefId};
1515
use rustc_hir::lang_items::LangItem;
@@ -114,7 +114,7 @@ impl From<DefId> for ItemId {
114114
pub(crate) struct Crate {
115115
pub(crate) module: Item,
116116
/// Only here so that they can be filtered through the rustdoc passes.
117-
pub(crate) external_traits: Box<FxHashMap<DefId, Trait>>,
117+
pub(crate) external_traits: Box<FxIndexMap<DefId, Trait>>,
118118
}
119119

120120
impl Crate {
@@ -1223,7 +1223,7 @@ impl Attributes {
12231223
}
12241224

12251225
pub(crate) fn get_doc_aliases(&self) -> Box<[Symbol]> {
1226-
let mut aliases = FxHashSet::default();
1226+
let mut aliases = FxIndexSet::default();
12271227

12281228
for attr in self.other_attrs.lists(sym::doc).filter(|a| a.has_name(sym::alias)) {
12291229
if let Some(values) = attr.meta_item_list() {
@@ -1759,7 +1759,7 @@ pub(crate) enum PrimitiveType {
17591759
Never,
17601760
}
17611761

1762-
type SimplifiedTypes = FxHashMap<PrimitiveType, ArrayVec<SimplifiedType, 3>>;
1762+
type SimplifiedTypes = FxIndexMap<PrimitiveType, ArrayVec<SimplifiedType, 3>>;
17631763
impl PrimitiveType {
17641764
pub(crate) fn from_hir(prim: hir::PrimTy) -> PrimitiveType {
17651765
use ast::{FloatTy, IntTy, UintTy};
@@ -1927,10 +1927,10 @@ impl PrimitiveType {
19271927
/// In particular, if a crate depends on both `std` and another crate that also defines
19281928
/// `rustc_doc_primitive`, then it's entirely random whether `std` or the other crate is picked.
19291929
/// (no_std crates are usually fine unless multiple dependencies define a primitive.)
1930-
pub(crate) fn primitive_locations(tcx: TyCtxt<'_>) -> &FxHashMap<PrimitiveType, DefId> {
1931-
static PRIMITIVE_LOCATIONS: OnceCell<FxHashMap<PrimitiveType, DefId>> = OnceCell::new();
1930+
pub(crate) fn primitive_locations(tcx: TyCtxt<'_>) -> &FxIndexMap<PrimitiveType, DefId> {
1931+
static PRIMITIVE_LOCATIONS: OnceCell<FxIndexMap<PrimitiveType, DefId>> = OnceCell::new();
19321932
PRIMITIVE_LOCATIONS.get_or_init(|| {
1933-
let mut primitive_locations = FxHashMap::default();
1933+
let mut primitive_locations = FxIndexMap::default();
19341934
// NOTE: technically this misses crates that are only passed with `--extern` and not loaded when checking the crate.
19351935
// This is a degenerate case that I don't plan to support.
19361936
for &crate_num in tcx.crates(()) {
@@ -2460,7 +2460,7 @@ pub(crate) struct Impl {
24602460
}
24612461

24622462
impl Impl {
2463-
pub(crate) fn provided_trait_methods(&self, tcx: TyCtxt<'_>) -> FxHashSet<Symbol> {
2463+
pub(crate) fn provided_trait_methods(&self, tcx: TyCtxt<'_>) -> FxIndexSet<Symbol> {
24642464
self.trait_
24652465
.as_ref()
24662466
.map(|t| t.def_id())

‎src/librustdoc/config.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::path::{Path, PathBuf};
55
use std::str::FromStr;
66
use std::{fmt, io};
77

8-
use rustc_data_structures::fx::FxHashMap;
8+
use rustc_data_structures::fx::FxIndexMap;
99
use rustc_errors::DiagCtxtHandle;
1010
use rustc_session::config::{
1111
self, CodegenOptions, CrateType, ErrorOutputType, Externs, Input, JsonUnusedExterns,
@@ -249,7 +249,7 @@ pub(crate) struct RenderOptions {
249249
pub(crate) extern_html_root_takes_precedence: bool,
250250
/// A map of the default settings (values are as for DOM storage API). Keys should lack the
251251
/// `rustdoc-` prefix.
252-
pub(crate) default_settings: FxHashMap<String, String>,
252+
pub(crate) default_settings: FxIndexMap<String, String>,
253253
/// If present, suffix added to CSS/JavaScript files when referencing them in generated pages.
254254
pub(crate) resource_suffix: String,
255255
/// Whether to create an index page in the root of the output directory. If this is true but

‎src/librustdoc/core.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::sync::atomic::AtomicBool;
22
use std::sync::{Arc, LazyLock};
33
use std::{io, mem};
44

5-
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
5+
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
66
use rustc_data_structures::sync::Lrc;
77
use rustc_data_structures::unord::UnordSet;
88
use rustc_errors::codes::*;
@@ -39,7 +39,7 @@ pub(crate) struct DocContext<'tcx> {
3939
/// Most of this logic is copied from rustc_lint::late.
4040
pub(crate) param_env: ParamEnv<'tcx>,
4141
/// Later on moved through `clean::Crate` into `cache`
42-
pub(crate) external_traits: FxHashMap<DefId, clean::Trait>,
42+
pub(crate) external_traits: FxIndexMap<DefId, clean::Trait>,
4343
/// Used while populating `external_traits` to ensure we don't process the same trait twice at
4444
/// the same time.
4545
pub(crate) active_extern_traits: DefIdSet,

‎src/librustdoc/doctest.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use std::{panic, str};
1414
pub(crate) use make::DocTestBuilder;
1515
pub(crate) use markdown::test as test_markdown;
1616
use rustc_ast as ast;
17-
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
17+
use rustc_data_structures::fx::{FxHashMap, FxIndexMap, FxIndexSet};
1818
use rustc_errors::{ColorConfig, DiagCtxtHandle, ErrorGuaranteed, FatalError};
1919
use rustc_hir::CRATE_HIR_ID;
2020
use rustc_hir::def_id::LOCAL_CRATE;
@@ -213,12 +213,13 @@ pub(crate) fn run(
213213
let unused_extern_reports: Vec<_> =
214214
std::mem::take(&mut unused_extern_reports.lock().unwrap());
215215
if unused_extern_reports.len() == compiling_test_count {
216-
let extern_names = externs.iter().map(|(name, _)| name).collect::<FxHashSet<&String>>();
216+
let extern_names =
217+
externs.iter().map(|(name, _)| name).collect::<FxIndexSet<&String>>();
217218
let mut unused_extern_names = unused_extern_reports
218219
.iter()
219-
.map(|uexts| uexts.unused_extern_names.iter().collect::<FxHashSet<&String>>())
220+
.map(|uexts| uexts.unused_extern_names.iter().collect::<FxIndexSet<&String>>())
220221
.fold(extern_names, |uextsa, uextsb| {
221-
uextsa.intersection(&uextsb).copied().collect::<FxHashSet<&String>>()
222+
uextsa.intersection(&uextsb).copied().collect::<FxIndexSet<&String>>()
222223
})
223224
.iter()
224225
.map(|v| (*v).clone())
@@ -253,7 +254,7 @@ pub(crate) fn run_tests(
253254
rustdoc_options: &Arc<RustdocOptions>,
254255
unused_extern_reports: &Arc<Mutex<Vec<UnusedExterns>>>,
255256
mut standalone_tests: Vec<test::TestDescAndFn>,
256-
mergeable_tests: FxHashMap<Edition, Vec<(DocTestBuilder, ScrapedDocTest)>>,
257+
mergeable_tests: FxIndexMap<Edition, Vec<(DocTestBuilder, ScrapedDocTest)>>,
257258
) {
258259
let mut test_args = Vec::with_capacity(rustdoc_options.test_args.len() + 1);
259260
test_args.insert(0, "rustdoctest".to_string());
@@ -775,7 +776,7 @@ pub(crate) trait DocTestVisitor {
775776

776777
struct CreateRunnableDocTests {
777778
standalone_tests: Vec<test::TestDescAndFn>,
778-
mergeable_tests: FxHashMap<Edition, Vec<(DocTestBuilder, ScrapedDocTest)>>,
779+
mergeable_tests: FxIndexMap<Edition, Vec<(DocTestBuilder, ScrapedDocTest)>>,
779780

780781
rustdoc_options: Arc<RustdocOptions>,
781782
opts: GlobalTestOptions,
@@ -790,7 +791,7 @@ impl CreateRunnableDocTests {
790791
let can_merge_doctests = rustdoc_options.edition >= Edition::Edition2024;
791792
CreateRunnableDocTests {
792793
standalone_tests: Vec::new(),
793-
mergeable_tests: FxHashMap::default(),
794+
mergeable_tests: FxIndexMap::default(),
794795
rustdoc_options: Arc::new(rustdoc_options),
795796
opts,
796797
visited_tests: FxHashMap::default(),

‎src/librustdoc/doctest/runner.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::fmt::Write;
22

3-
use rustc_data_structures::fx::FxHashSet;
3+
use rustc_data_structures::fx::FxIndexSet;
44
use rustc_span::edition::Edition;
55

66
use crate::doctest::{
@@ -11,7 +11,7 @@ use crate::html::markdown::{Ignore, LangString};
1111

1212
/// Convenient type to merge compatible doctests into one.
1313
pub(crate) struct DocTestRunner {
14-
crate_attrs: FxHashSet<String>,
14+
crate_attrs: FxIndexSet<String>,
1515
ids: String,
1616
output: String,
1717
supports_color: bool,
@@ -21,7 +21,7 @@ pub(crate) struct DocTestRunner {
2121
impl DocTestRunner {
2222
pub(crate) fn new() -> Self {
2323
Self {
24-
crate_attrs: FxHashSet::default(),
24+
crate_attrs: FxIndexSet::default(),
2525
ids: String::new(),
2626
output: String::new(),
2727
supports_color: true,

‎src/librustdoc/formats/cache.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::mem;
22

3-
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet};
3+
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet};
44
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, DefIdSet};
55
use rustc_middle::ty::{self, TyCtxt};
66
use rustc_span::Symbol;
@@ -42,7 +42,7 @@ pub(crate) struct Cache {
4242
/// URLs when a type is being linked to. External paths are not located in
4343
/// this map because the `External` type itself has all the information
4444
/// necessary.
45-
pub(crate) paths: FxHashMap<DefId, (Vec<Symbol>, ItemType)>,
45+
pub(crate) paths: FxIndexMap<DefId, (Vec<Symbol>, ItemType)>,
4646

4747
/// Similar to `paths`, but only holds external paths. This is only used for
4848
/// generating explicit hyperlinks to other crates.
@@ -64,18 +64,18 @@ pub(crate) struct Cache {
6464
/// Implementations of a crate should inherit the documentation of the
6565
/// parent trait if no extra documentation is specified, and default methods
6666
/// should show up in documentation about trait implementations.
67-
pub(crate) traits: FxHashMap<DefId, clean::Trait>,
67+
pub(crate) traits: FxIndexMap<DefId, clean::Trait>,
6868

6969
/// When rendering traits, it's often useful to be able to list all
7070
/// implementors of the trait, and this mapping is exactly, that: a mapping
7171
/// of trait ids to the list of known implementors of the trait
72-
pub(crate) implementors: FxHashMap<DefId, Vec<Impl>>,
72+
pub(crate) implementors: FxIndexMap<DefId, Vec<Impl>>,
7373

7474
/// Cache of where external crate documentation can be found.
75-
pub(crate) extern_locations: FxHashMap<CrateNum, ExternalLocation>,
75+
pub(crate) extern_locations: FxIndexMap<CrateNum, ExternalLocation>,
7676

7777
/// Cache of where documentation for primitives can be found.
78-
pub(crate) primitive_locations: FxHashMap<clean::PrimitiveType, DefId>,
78+
pub(crate) primitive_locations: FxIndexMap<clean::PrimitiveType, DefId>,
7979

8080
// Note that external items for which `doc(hidden)` applies to are shown as
8181
// non-reachable while local items aren't. This is because we're reusing
@@ -118,7 +118,7 @@ pub(crate) struct Cache {
118118
// crawl. In order to prevent crashes when looking for notable traits or
119119
// when gathering trait documentation on a type, hold impls here while
120120
// folding and add them to the cache later on if we find the trait.
121-
orphan_trait_impls: Vec<(DefId, FxHashSet<DefId>, Impl)>,
121+
orphan_trait_impls: Vec<(DefId, FxIndexSet<DefId>, Impl)>,
122122

123123
/// All intra-doc links resolved so far.
124124
///
@@ -376,7 +376,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
376376
// Figure out the id of this impl. This may map to a
377377
// primitive rather than always to a struct/enum.
378378
// Note: matching twice to restrict the lifetime of the `i` borrow.
379-
let mut dids = FxHashSet::default();
379+
let mut dids = FxIndexSet::default();
380380
match i.for_ {
381381
clean::Type::Path { ref path }
382382
| clean::BorrowedRef { type_: box clean::Type::Path { ref path }, .. } => {

‎src/librustdoc/html/highlight.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use std::collections::VecDeque;
99
use std::fmt::{Display, Write};
1010

11-
use rustc_data_structures::fx::FxHashMap;
11+
use rustc_data_structures::fx::FxIndexMap;
1212
use rustc_lexer::{Cursor, LiteralKind, TokenKind};
1313
use rustc_span::edition::Edition;
1414
use rustc_span::symbol::Symbol;
@@ -34,7 +34,7 @@ pub(crate) struct HrefContext<'a, 'tcx> {
3434
/// Decorations are represented as a map from CSS class to vector of character ranges.
3535
/// Each range will be wrapped in a span with that class.
3636
#[derive(Default)]
37-
pub(crate) struct DecorationInfo(pub(crate) FxHashMap<&'static str, Vec<(u32, u32)>>);
37+
pub(crate) struct DecorationInfo(pub(crate) FxIndexMap<&'static str, Vec<(u32, u32)>>);
3838

3939
#[derive(Eq, PartialEq, Clone, Copy)]
4040
pub(crate) enum Tooltip {

‎src/librustdoc/html/highlight/tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use expect_test::expect_file;
2-
use rustc_data_structures::fx::FxHashMap;
2+
use rustc_data_structures::fx::FxIndexMap;
33
use rustc_span::create_default_session_globals_then;
44

55
use super::{DecorationInfo, write_code};
@@ -73,7 +73,7 @@ fn test_decorations() {
7373
let y = 2;
7474
let z = 3;
7575
let a = 4;";
76-
let mut decorations = FxHashMap::default();
76+
let mut decorations = FxIndexMap::default();
7777
decorations.insert("example", vec![(0, 10), (11, 21)]);
7878
decorations.insert("example2", vec![(22, 32)]);
7979

‎src/librustdoc/html/layout.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::path::PathBuf;
22

33
use rinja::Template;
4-
use rustc_data_structures::fx::FxHashMap;
4+
use rustc_data_structures::fx::FxIndexMap;
55

66
use super::static_files::{STATIC_FILES, StaticFiles};
77
use crate::externalfiles::ExternalHtml;
@@ -13,7 +13,7 @@ pub(crate) struct Layout {
1313
pub(crate) logo: String,
1414
pub(crate) favicon: String,
1515
pub(crate) external_html: ExternalHtml,
16-
pub(crate) default_settings: FxHashMap<String, String>,
16+
pub(crate) default_settings: FxIndexMap<String, String>,
1717
pub(crate) krate: String,
1818
pub(crate) krate_version: String,
1919
/// The given user css file which allow to customize the generated

‎src/librustdoc/html/markdown.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use pulldown_cmark::{
3838
BrokenLink, BrokenLinkCallback, CodeBlockKind, CowStr, Event, LinkType, OffsetIter, Options,
3939
Parser, Tag, TagEnd, html,
4040
};
41-
use rustc_data_structures::fx::FxHashMap;
41+
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
4242
use rustc_errors::{Diag, DiagMessage};
4343
use rustc_hir::def_id::LocalDefId;
4444
use rustc_middle::ty::TyCtxt;
@@ -651,12 +651,12 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for SummaryLine<'a, I> {
651651
/// references.
652652
struct Footnotes<'a, I> {
653653
inner: I,
654-
footnotes: FxHashMap<String, (Vec<Event<'a>>, u16)>,
654+
footnotes: FxIndexMap<String, (Vec<Event<'a>>, u16)>,
655655
}
656656

657657
impl<'a, I> Footnotes<'a, I> {
658658
fn new(iter: I) -> Self {
659-
Footnotes { inner: iter, footnotes: FxHashMap::default() }
659+
Footnotes { inner: iter, footnotes: FxIndexMap::default() }
660660
}
661661

662662
fn get_entry(&mut self, key: &str) -> &mut (Vec<Event<'a>>, u16) {
@@ -694,7 +694,7 @@ impl<'a, I: Iterator<Item = SpannedEvent<'a>>> Iterator for Footnotes<'a, I> {
694694
Some(e) => return Some(e),
695695
None => {
696696
if !self.footnotes.is_empty() {
697-
let mut v: Vec<_> = self.footnotes.drain().map(|(_, x)| x).collect();
697+
let mut v: Vec<_> = self.footnotes.drain(..).map(|(_, x)| x).collect();
698698
v.sort_by(|a, b| a.1.cmp(&b.1));
699699
let mut ret = String::from("<div class=\"footnotes\"><hr><ol>");
700700
for (mut content, id) in v {

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::rc::Rc;
66
use std::sync::mpsc::{Receiver, channel};
77

88
use rinja::Template;
9-
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
9+
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet};
1010
use rustc_hir::def_id::{DefIdMap, LOCAL_CRATE};
1111
use rustc_middle::ty::TyCtxt;
1212
use rustc_session::Session;
@@ -69,14 +69,14 @@ pub(crate) struct Context<'tcx> {
6969
/// `true`.
7070
pub(crate) include_sources: bool,
7171
/// Collection of all types with notable traits referenced in the current module.
72-
pub(crate) types_with_notable_traits: FxHashSet<clean::Type>,
72+
pub(crate) types_with_notable_traits: FxIndexSet<clean::Type>,
7373
/// Field used during rendering, to know if we're inside an inlined item.
7474
pub(crate) is_inside_inlined_module: bool,
7575
}
7676

7777
// `Context` is cloned a lot, so we don't want the size to grow unexpectedly.
7878
#[cfg(all(not(windows), target_pointer_width = "64"))]
79-
rustc_data_structures::static_assert_size!(Context<'_>, 160);
79+
rustc_data_structures::static_assert_size!(Context<'_>, 184);
8080
#[cfg(all(windows, target_pointer_width = "64"))]
8181
rustc_data_structures::static_assert_size!(Context<'_>, 168);
8282

@@ -90,7 +90,7 @@ pub(crate) struct SharedContext<'tcx> {
9090
/// creation of the context (contains info like the favicon and added html).
9191
pub(crate) layout: layout::Layout,
9292
/// The local file sources we've emitted and their respective url-paths.
93-
pub(crate) local_sources: FxHashMap<PathBuf, String>,
93+
pub(crate) local_sources: FxIndexMap<PathBuf, String>,
9494
/// Show the memory layout of types in the docs.
9595
pub(super) show_type_layout: bool,
9696
/// The base-URL of the issue tracker for when an item has been tagged with
@@ -567,7 +567,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
567567
deref_id_map: Default::default(),
568568
shared: Rc::new(scx),
569569
include_sources,
570-
types_with_notable_traits: FxHashSet::default(),
570+
types_with_notable_traits: FxIndexSet::default(),
571571
is_inside_inlined_module: false,
572572
};
573573

@@ -591,7 +591,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
591591
id_map: IdMap::new(),
592592
shared: Rc::clone(&self.shared),
593593
include_sources: self.include_sources,
594-
types_with_notable_traits: FxHashSet::default(),
594+
types_with_notable_traits: FxIndexSet::default(),
595595
is_inside_inlined_module: self.is_inside_inlined_module,
596596
}
597597
}

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

+19-19
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ use std::{fs, str};
4747
use rinja::Template;
4848
use rustc_attr::{ConstStability, DeprecatedSince, Deprecation, StabilityLevel, StableSince};
4949
use rustc_data_structures::captures::Captures;
50-
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
50+
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
5151
use rustc_hir::Mutability;
5252
use rustc_hir::def_id::{DefId, DefIdSet};
5353
use rustc_middle::ty::print::PrintTraitRefExt;
@@ -328,24 +328,24 @@ impl Ord for ItemEntry {
328328

329329
#[derive(Debug)]
330330
struct AllTypes {
331-
structs: FxHashSet<ItemEntry>,
332-
enums: FxHashSet<ItemEntry>,
333-
unions: FxHashSet<ItemEntry>,
334-
primitives: FxHashSet<ItemEntry>,
335-
traits: FxHashSet<ItemEntry>,
336-
macros: FxHashSet<ItemEntry>,
337-
functions: FxHashSet<ItemEntry>,
338-
type_aliases: FxHashSet<ItemEntry>,
339-
statics: FxHashSet<ItemEntry>,
340-
constants: FxHashSet<ItemEntry>,
341-
attribute_macros: FxHashSet<ItemEntry>,
342-
derive_macros: FxHashSet<ItemEntry>,
343-
trait_aliases: FxHashSet<ItemEntry>,
331+
structs: FxIndexSet<ItemEntry>,
332+
enums: FxIndexSet<ItemEntry>,
333+
unions: FxIndexSet<ItemEntry>,
334+
primitives: FxIndexSet<ItemEntry>,
335+
traits: FxIndexSet<ItemEntry>,
336+
macros: FxIndexSet<ItemEntry>,
337+
functions: FxIndexSet<ItemEntry>,
338+
type_aliases: FxIndexSet<ItemEntry>,
339+
statics: FxIndexSet<ItemEntry>,
340+
constants: FxIndexSet<ItemEntry>,
341+
attribute_macros: FxIndexSet<ItemEntry>,
342+
derive_macros: FxIndexSet<ItemEntry>,
343+
trait_aliases: FxIndexSet<ItemEntry>,
344344
}
345345

346346
impl AllTypes {
347347
fn new() -> AllTypes {
348-
let new_set = |cap| FxHashSet::with_capacity_and_hasher(cap, Default::default());
348+
let new_set = |cap| FxIndexSet::with_capacity_and_hasher(cap, Default::default());
349349
AllTypes {
350350
structs: new_set(100),
351351
enums: new_set(100),
@@ -437,7 +437,7 @@ impl AllTypes {
437437
}
438438

439439
fn print(self, f: &mut Buffer) {
440-
fn print_entries(f: &mut Buffer, e: &FxHashSet<ItemEntry>, kind: ItemSection) {
440+
fn print_entries(f: &mut Buffer, e: &FxIndexSet<ItemEntry>, kind: ItemSection) {
441441
if !e.is_empty() {
442442
let mut e: Vec<&ItemEntry> = e.iter().collect();
443443
e.sort();
@@ -1151,7 +1151,7 @@ fn render_attributes_in_code(w: &mut impl fmt::Write, it: &clean::Item, cx: &Con
11511151
#[derive(Copy, Clone)]
11521152
enum AssocItemLink<'a> {
11531153
Anchor(Option<&'a str>),
1154-
GotoSource(ItemId, &'a FxHashSet<Symbol>),
1154+
GotoSource(ItemId, &'a FxIndexSet<Symbol>),
11551155
}
11561156

11571157
impl<'a> AssocItemLink<'a> {
@@ -1494,7 +1494,7 @@ fn notable_traits_decl(ty: &clean::Type, cx: &Context<'_>) -> (String, String) {
14941494
for it in &impl_.items {
14951495
if let clean::AssocTypeItem(ref tydef, ref _bounds) = it.kind {
14961496
out.push_str("<div class=\"where\"> ");
1497-
let empty_set = FxHashSet::default();
1497+
let empty_set = FxIndexSet::default();
14981498
let src_link = AssocItemLink::GotoSource(trait_did.into(), &empty_set);
14991499
assoc_type(
15001500
&mut out,
@@ -2526,7 +2526,7 @@ fn render_call_locations<W: fmt::Write>(mut w: W, cx: &mut Context<'_>, item: &c
25262526
})()
25272527
.unwrap_or(DUMMY_SP);
25282528

2529-
let mut decoration_info = FxHashMap::default();
2529+
let mut decoration_info = FxIndexMap::default();
25302530
decoration_info.insert("highlight focus", vec![byte_ranges.remove(0)]);
25312531
decoration_info.insert("highlight", byte_ranges);
25322532

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::rc::Rc;
66
use itertools::Itertools;
77
use rinja::Template;
88
use rustc_data_structures::captures::Captures;
9-
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
9+
use rustc_data_structures::fx::{FxHashMap, FxIndexSet};
1010
use rustc_hir as hir;
1111
use rustc_hir::def::CtorKind;
1212
use rustc_hir::def_id::DefId;
@@ -932,7 +932,7 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
932932

933933
let cloned_shared = Rc::clone(&cx.shared);
934934
let cache = &cloned_shared.cache;
935-
let mut extern_crates = FxHashSet::default();
935+
let mut extern_crates = FxIndexSet::default();
936936

937937
if !t.is_object_safe(cx.tcx()) {
938938
write_section_heading(

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ pub(crate) fn get_function_type_for_search<'tcx>(
774774
fn get_index_type(
775775
clean_type: &clean::Type,
776776
generics: Vec<RenderType>,
777-
rgen: &mut FxHashMap<SimplifiedParam, (isize, Vec<RenderType>)>,
777+
rgen: &mut FxIndexMap<SimplifiedParam, (isize, Vec<RenderType>)>,
778778
) -> RenderType {
779779
RenderType {
780780
id: get_index_type_id(clean_type, rgen),
@@ -785,7 +785,7 @@ fn get_index_type(
785785

786786
fn get_index_type_id(
787787
clean_type: &clean::Type,
788-
rgen: &mut FxHashMap<SimplifiedParam, (isize, Vec<RenderType>)>,
788+
rgen: &mut FxIndexMap<SimplifiedParam, (isize, Vec<RenderType>)>,
789789
) -> Option<RenderTypeId> {
790790
use rustc_hir::def::{DefKind, Res};
791791
match *clean_type {
@@ -854,7 +854,7 @@ fn simplify_fn_type<'a, 'tcx>(
854854
tcx: TyCtxt<'tcx>,
855855
recurse: usize,
856856
res: &mut Vec<RenderType>,
857-
rgen: &mut FxHashMap<SimplifiedParam, (isize, Vec<RenderType>)>,
857+
rgen: &mut FxIndexMap<SimplifiedParam, (isize, Vec<RenderType>)>,
858858
is_return: bool,
859859
cache: &Cache,
860860
) {
@@ -1198,7 +1198,7 @@ fn simplify_fn_constraint<'a, 'tcx>(
11981198
tcx: TyCtxt<'tcx>,
11991199
recurse: usize,
12001200
res: &mut Vec<(RenderTypeId, Vec<RenderType>)>,
1201-
rgen: &mut FxHashMap<SimplifiedParam, (isize, Vec<RenderType>)>,
1201+
rgen: &mut FxIndexMap<SimplifiedParam, (isize, Vec<RenderType>)>,
12021202
is_return: bool,
12031203
cache: &Cache,
12041204
) {
@@ -1285,7 +1285,7 @@ fn get_fn_inputs_and_outputs<'tcx>(
12851285
) -> (Vec<RenderType>, Vec<RenderType>, Vec<Vec<RenderType>>) {
12861286
let decl = &func.decl;
12871287

1288-
let mut rgen: FxHashMap<SimplifiedParam, (isize, Vec<RenderType>)> = Default::default();
1288+
let mut rgen: FxIndexMap<SimplifiedParam, (isize, Vec<RenderType>)> = Default::default();
12891289

12901290
let combined_generics;
12911291
let (self_, generics) = if let Some((impl_self, impl_generics)) = impl_or_trait_generics {

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::path::{Path, PathBuf};
22

3-
use rustc_data_structures::fx::FxHashMap;
3+
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
44
use rustc_hir::def::{DefKind, Res};
55
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
66
use rustc_hir::intravisit::{self, Visitor};
@@ -44,7 +44,7 @@ pub(crate) fn collect_spans_and_sources(
4444
src_root: &Path,
4545
include_sources: bool,
4646
generate_link_to_definition: bool,
47-
) -> (FxHashMap<PathBuf, String>, FxHashMap<Span, LinkFromSrc>) {
47+
) -> (FxIndexMap<PathBuf, String>, FxHashMap<Span, LinkFromSrc>) {
4848
let mut visitor = SpanMapVisitor { tcx, matches: FxHashMap::default() };
4949

5050
if include_sources {

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use indexmap::IndexMap;
2828
use itertools::Itertools;
2929
use regex::Regex;
3030
use rustc_data_structures::flock;
31-
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
31+
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
3232
use rustc_middle::ty::TyCtxt;
3333
use rustc_middle::ty::fast_reject::DeepRejectCtxt;
3434
use rustc_span::Symbol;
@@ -505,8 +505,8 @@ createSrcSidebar();",
505505
struct Hierarchy {
506506
parent: Weak<Self>,
507507
elem: OsString,
508-
children: RefCell<FxHashMap<OsString, Rc<Self>>>,
509-
elems: RefCell<FxHashSet<OsString>>,
508+
children: RefCell<FxIndexMap<OsString, Rc<Self>>>,
509+
elems: RefCell<FxIndexSet<OsString>>,
510510
}
511511

512512
impl Hierarchy {
@@ -961,8 +961,8 @@ impl Serialize for AliasSerializableImpl {
961961
fn get_path_parts<T: CciPart>(
962962
dst: &Path,
963963
crates_info: &[CrateInfo],
964-
) -> FxHashMap<PathBuf, Vec<String>> {
965-
let mut templates: FxHashMap<PathBuf, Vec<String>> = FxHashMap::default();
964+
) -> FxIndexMap<PathBuf, Vec<String>> {
965+
let mut templates: FxIndexMap<PathBuf, Vec<String>> = FxIndexMap::default();
966966
crates_info
967967
.iter()
968968
.map(|crate_info| T::from_crate_info(crate_info).parts.iter())

‎src/librustdoc/html/sources.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::rc::Rc;
66
use std::{fmt, fs};
77

88
use rinja::Template;
9-
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
9+
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
1010
use rustc_hir::def_id::LOCAL_CRATE;
1111
use rustc_middle::ty::TyCtxt;
1212
use rustc_session::Session;
@@ -39,15 +39,15 @@ pub(crate) fn collect_local_sources<'tcx>(
3939
tcx: TyCtxt<'tcx>,
4040
src_root: &Path,
4141
krate: &clean::Crate,
42-
) -> FxHashMap<PathBuf, String> {
43-
let mut lsc = LocalSourcesCollector { tcx, local_sources: FxHashMap::default(), src_root };
42+
) -> FxIndexMap<PathBuf, String> {
43+
let mut lsc = LocalSourcesCollector { tcx, local_sources: FxIndexMap::default(), src_root };
4444
lsc.visit_crate(krate);
4545
lsc.local_sources
4646
}
4747

4848
struct LocalSourcesCollector<'a, 'tcx> {
4949
tcx: TyCtxt<'tcx>,
50-
local_sources: FxHashMap<PathBuf, String>,
50+
local_sources: FxIndexMap<PathBuf, String>,
5151
src_root: &'a Path,
5252
}
5353

‎src/librustdoc/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#![warn(rustc::internal)]
2121
#![allow(clippy::collapsible_if, clippy::collapsible_else_if)]
2222
#![allow(rustc::diagnostic_outside_of_impl)]
23-
#![allow(rustc::potential_query_instability)]
2423
#![allow(rustc::untranslatable_diagnostic)]
2524

2625
extern crate thin_vec;
@@ -99,7 +98,7 @@ use crate::clean::utils::DOC_RUST_LANG_ORG_CHANNEL;
9998
/// Commas between elements are required (even if the expression is a block).
10099
macro_rules! map {
101100
($( $key: expr => $val: expr ),* $(,)*) => {{
102-
let mut map = ::rustc_data_structures::fx::FxHashMap::default();
101+
let mut map = ::rustc_data_structures::fx::FxIndexMap::default();
103102
$( map.insert($key, $val); )*
104103
map
105104
}}

‎src/librustdoc/passes/collect_intra_doc_links.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::ops::Range;
99

1010
use pulldown_cmark::LinkType;
1111
use rustc_ast::util::comments::may_have_doc_links;
12-
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
12+
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet};
1313
use rustc_data_structures::intern::Interned;
1414
use rustc_errors::{Applicability, Diag, DiagMessage};
1515
use rustc_hir::def::Namespace::*;
@@ -778,9 +778,9 @@ fn trait_impls_for<'a>(
778778
cx: &mut DocContext<'a>,
779779
ty: Ty<'a>,
780780
module: DefId,
781-
) -> FxHashSet<(DefId, DefId)> {
781+
) -> FxIndexSet<(DefId, DefId)> {
782782
let tcx = cx.tcx;
783-
let mut impls = FxHashSet::default();
783+
let mut impls = FxIndexSet::default();
784784

785785
for &trait_ in tcx.doc_link_traits_in_scope(module) {
786786
tcx.for_each_relevant_impl(trait_, ty, |impl_| {

‎src/librustdoc/passes/collect_trait_impls.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ pub(crate) fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) ->
219219
panic!("collect-trait-impls can't run");
220220
};
221221

222-
krate.external_traits.extend(cx.external_traits.drain());
222+
krate.external_traits.extend(cx.external_traits.drain(..));
223223

224224
krate
225225
}

‎src/librustdoc/scrape_examples.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use std::fs;
44
use std::path::PathBuf;
55

6-
use rustc_data_structures::fx::FxHashMap;
6+
use rustc_data_structures::fx::FxIndexMap;
77
use rustc_errors::DiagCtxtHandle;
88
use rustc_hir::intravisit::{self, Visitor};
99
use rustc_hir::{self as hir};
@@ -102,8 +102,8 @@ pub(crate) struct CallData {
102102
pub(crate) is_bin: bool,
103103
}
104104

105-
pub(crate) type FnCallLocations = FxHashMap<PathBuf, CallData>;
106-
pub(crate) type AllCallLocations = FxHashMap<DefPathHash, FnCallLocations>;
105+
pub(crate) type FnCallLocations = FxIndexMap<PathBuf, CallData>;
106+
pub(crate) type AllCallLocations = FxIndexMap<DefPathHash, FnCallLocations>;
107107

108108
/// Visitor for traversing a crate and finding instances of function calls.
109109
struct FindCalls<'a, 'tcx> {
@@ -293,7 +293,7 @@ pub(crate) fn run(
293293
debug!("Scrape examples target_crates: {target_crates:?}");
294294

295295
// Run call-finder on all items
296-
let mut calls = FxHashMap::default();
296+
let mut calls = FxIndexMap::default();
297297
let mut finder =
298298
FindCalls { calls: &mut calls, tcx, map: tcx.hir(), cx, target_crates, bin_crate };
299299
tcx.hir().visit_all_item_likes_in_crate(&mut finder);
@@ -332,7 +332,7 @@ pub(crate) fn load_call_locations(
332332
with_examples: Vec<String>,
333333
dcx: DiagCtxtHandle<'_>,
334334
) -> AllCallLocations {
335-
let mut all_calls: AllCallLocations = FxHashMap::default();
335+
let mut all_calls: AllCallLocations = FxIndexMap::default();
336336
for path in with_examples {
337337
let bytes = match fs::read(&path) {
338338
Ok(bytes) => bytes,

‎src/librustdoc/theme.rs

+16-17
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
use std::collections::hash_map::Entry;
21
use std::fs;
32
use std::iter::Peekable;
43
use std::path::Path;
54
use std::str::Chars;
65

7-
use rustc_data_structures::fx::FxHashMap;
6+
use rustc_data_structures::fx::{FxIndexMap, IndexEntry};
87
use rustc_errors::DiagCtxtHandle;
98

109
#[cfg(test)]
1110
mod tests;
1211

1312
#[derive(Debug)]
1413
pub(crate) struct CssPath {
15-
pub(crate) rules: FxHashMap<String, String>,
16-
pub(crate) children: FxHashMap<String, CssPath>,
14+
pub(crate) rules: FxIndexMap<String, String>,
15+
pub(crate) children: FxIndexMap<String, CssPath>,
1716
}
1817

1918
/// When encountering a `"` or a `'`, returns the whole string, including the quote characters.
@@ -120,10 +119,10 @@ fn parse_rules(
120119
content: &str,
121120
selector: String,
122121
iter: &mut Peekable<Chars<'_>>,
123-
paths: &mut FxHashMap<String, CssPath>,
122+
paths: &mut FxIndexMap<String, CssPath>,
124123
) -> Result<(), String> {
125-
let mut rules = FxHashMap::default();
126-
let mut children = FxHashMap::default();
124+
let mut rules = FxIndexMap::default();
125+
let mut children = FxIndexMap::default();
127126

128127
loop {
129128
// If the parent isn't a "normal" CSS selector, we only expect sub-selectors and not CSS
@@ -146,10 +145,10 @@ fn parse_rules(
146145
return Err(format!("Found empty value for rule `{rule}` in selector `{selector}`"));
147146
}
148147
match rules.entry(rule) {
149-
Entry::Occupied(mut o) => {
148+
IndexEntry::Occupied(mut o) => {
150149
*o.get_mut() = value;
151150
}
152-
Entry::Vacant(v) => {
151+
IndexEntry::Vacant(v) => {
153152
v.insert(value);
154153
}
155154
}
@@ -159,7 +158,7 @@ fn parse_rules(
159158
}
160159

161160
match paths.entry(selector) {
162-
Entry::Occupied(mut o) => {
161+
IndexEntry::Occupied(mut o) => {
163162
let v = o.get_mut();
164163
for (key, value) in rules.into_iter() {
165164
v.rules.insert(key, value);
@@ -168,7 +167,7 @@ fn parse_rules(
168167
v.children.insert(sel, child);
169168
}
170169
}
171-
Entry::Vacant(v) => {
170+
IndexEntry::Vacant(v) => {
172171
v.insert(CssPath { rules, children });
173172
}
174173
}
@@ -178,7 +177,7 @@ fn parse_rules(
178177
pub(crate) fn parse_selectors(
179178
content: &str,
180179
iter: &mut Peekable<Chars<'_>>,
181-
paths: &mut FxHashMap<String, CssPath>,
180+
paths: &mut FxIndexMap<String, CssPath>,
182181
) -> Result<(), String> {
183182
let mut selector = String::new();
184183

@@ -202,17 +201,17 @@ pub(crate) fn parse_selectors(
202201

203202
/// The entry point to parse the CSS rules. Every time we encounter a `{`, we then parse the rules
204203
/// inside it.
205-
pub(crate) fn load_css_paths(content: &str) -> Result<FxHashMap<String, CssPath>, String> {
204+
pub(crate) fn load_css_paths(content: &str) -> Result<FxIndexMap<String, CssPath>, String> {
206205
let mut iter = content.chars().peekable();
207-
let mut paths = FxHashMap::default();
206+
let mut paths = FxIndexMap::default();
208207

209208
parse_selectors(content, &mut iter, &mut paths)?;
210209
Ok(paths)
211210
}
212211

213212
pub(crate) fn get_differences(
214-
origin: &FxHashMap<String, CssPath>,
215-
against: &FxHashMap<String, CssPath>,
213+
origin: &FxIndexMap<String, CssPath>,
214+
against: &FxIndexMap<String, CssPath>,
216215
v: &mut Vec<String>,
217216
) {
218217
for (selector, entry) in origin.iter() {
@@ -235,7 +234,7 @@ pub(crate) fn get_differences(
235234

236235
pub(crate) fn test_theme_against<P: AsRef<Path>>(
237236
f: &P,
238-
origin: &FxHashMap<String, CssPath>,
237+
origin: &FxIndexMap<String, CssPath>,
239238
dcx: DiagCtxtHandle<'_>,
240239
) -> (bool, Vec<String>) {
241240
let against = match fs::read_to_string(f)

0 commit comments

Comments
 (0)
Please sign in to comment.