Skip to content

Commit 373971a

Browse files
committed
Auto merge of #131259 - ismailarilik:handle-potential-query-instability-lint-for-librustdoc, r=notriddle
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: #84447 r? `@compiler-errors`
2 parents 96d9d8a + e0a20b4 commit 373971a

23 files changed

+114
-115
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

+7-7
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,16 +69,16 @@ 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"))]
81-
rustc_data_structures::static_assert_size!(Context<'_>, 168);
81+
rustc_data_structures::static_assert_size!(Context<'_>, 192);
8282

8383
/// Shared mutable state used in [`Context`] and elsewhere.
8484
pub(crate) struct SharedContext<'tcx> {
@@ -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
}

0 commit comments

Comments
 (0)