Skip to content

Commit

Permalink
Auto merge of #131259 - ismailarilik:handle-potential-query-instabili…
Browse files Browse the repository at this point in the history
…ty-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`
  • Loading branch information
bors committed Oct 6, 2024
2 parents 96d9d8a + e0a20b4 commit 373971a
Show file tree
Hide file tree
Showing 23 changed files with 114 additions and 115 deletions.
6 changes: 3 additions & 3 deletions compiler/rustc_resolve/src/rustdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use pulldown_cmark::{
};
use rustc_ast as ast;
use rustc_ast::util::comments::beautify_doc_string;
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::fx::FxIndexMap;
use rustc_middle::ty::TyCtxt;
use rustc_span::def_id::DefId;
use rustc_span::symbol::{Symbol, kw, sym};
Expand Down Expand Up @@ -235,8 +235,8 @@ fn span_for_value(attr: &ast::Attribute) -> Span {
/// early and late doc link resolution regardless of their position.
pub fn prepare_to_doc_link_resolution(
doc_fragments: &[DocFragment],
) -> FxHashMap<Option<DefId>, String> {
let mut res = FxHashMap::default();
) -> FxIndexMap<Option<DefId>, String> {
let mut res = FxIndexMap::default();
for fragment in doc_fragments {
let out_str = res.entry(fragment.item_id).or_default();
add_doc_fragment(out_str, fragment);
Expand Down
16 changes: 8 additions & 8 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use rustc_ast::NestedMetaItem;
use rustc_ast_pretty::pprust;
use rustc_attr::{ConstStability, Deprecation, Stability, StableSince};
use rustc_const_eval::const_eval::is_unstable_const_fn;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
use rustc_hir::def::{CtorKind, DefKind, Res};
use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE, LocalDefId};
use rustc_hir::lang_items::LangItem;
Expand Down Expand Up @@ -114,7 +114,7 @@ impl From<DefId> for ItemId {
pub(crate) struct Crate {
pub(crate) module: Item,
/// Only here so that they can be filtered through the rustdoc passes.
pub(crate) external_traits: Box<FxHashMap<DefId, Trait>>,
pub(crate) external_traits: Box<FxIndexMap<DefId, Trait>>,
}

impl Crate {
Expand Down Expand Up @@ -1223,7 +1223,7 @@ impl Attributes {
}

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

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

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

impl Impl {
pub(crate) fn provided_trait_methods(&self, tcx: TyCtxt<'_>) -> FxHashSet<Symbol> {
pub(crate) fn provided_trait_methods(&self, tcx: TyCtxt<'_>) -> FxIndexSet<Symbol> {
self.trait_
.as_ref()
.map(|t| t.def_id())
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::{fmt, io};

use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::fx::FxIndexMap;
use rustc_errors::DiagCtxtHandle;
use rustc_session::config::{
self, CodegenOptions, CrateType, ErrorOutputType, Externs, Input, JsonUnusedExterns,
Expand Down Expand Up @@ -249,7 +249,7 @@ pub(crate) struct RenderOptions {
pub(crate) extern_html_root_takes_precedence: bool,
/// A map of the default settings (values are as for DOM storage API). Keys should lack the
/// `rustdoc-` prefix.
pub(crate) default_settings: FxHashMap<String, String>,
pub(crate) default_settings: FxIndexMap<String, String>,
/// If present, suffix added to CSS/JavaScript files when referencing them in generated pages.
pub(crate) resource_suffix: String,
/// Whether to create an index page in the root of the output directory. If this is true but
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::sync::atomic::AtomicBool;
use std::sync::{Arc, LazyLock};
use std::{io, mem};

use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
use rustc_data_structures::sync::Lrc;
use rustc_data_structures::unord::UnordSet;
use rustc_errors::codes::*;
Expand Down Expand Up @@ -39,7 +39,7 @@ pub(crate) struct DocContext<'tcx> {
/// Most of this logic is copied from rustc_lint::late.
pub(crate) param_env: ParamEnv<'tcx>,
/// Later on moved through `clean::Crate` into `cache`
pub(crate) external_traits: FxHashMap<DefId, clean::Trait>,
pub(crate) external_traits: FxIndexMap<DefId, clean::Trait>,
/// Used while populating `external_traits` to ensure we don't process the same trait twice at
/// the same time.
pub(crate) active_extern_traits: DefIdSet,
Expand Down
15 changes: 8 additions & 7 deletions src/librustdoc/doctest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use std::{panic, str};
pub(crate) use make::DocTestBuilder;
pub(crate) use markdown::test as test_markdown;
use rustc_ast as ast;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::fx::{FxHashMap, FxIndexMap, FxIndexSet};
use rustc_errors::{ColorConfig, DiagCtxtHandle, ErrorGuaranteed, FatalError};
use rustc_hir::CRATE_HIR_ID;
use rustc_hir::def_id::LOCAL_CRATE;
Expand Down Expand Up @@ -213,12 +213,13 @@ pub(crate) fn run(
let unused_extern_reports: Vec<_> =
std::mem::take(&mut unused_extern_reports.lock().unwrap());
if unused_extern_reports.len() == compiling_test_count {
let extern_names = externs.iter().map(|(name, _)| name).collect::<FxHashSet<&String>>();
let extern_names =
externs.iter().map(|(name, _)| name).collect::<FxIndexSet<&String>>();
let mut unused_extern_names = unused_extern_reports
.iter()
.map(|uexts| uexts.unused_extern_names.iter().collect::<FxHashSet<&String>>())
.map(|uexts| uexts.unused_extern_names.iter().collect::<FxIndexSet<&String>>())
.fold(extern_names, |uextsa, uextsb| {
uextsa.intersection(&uextsb).copied().collect::<FxHashSet<&String>>()
uextsa.intersection(&uextsb).copied().collect::<FxIndexSet<&String>>()
})
.iter()
.map(|v| (*v).clone())
Expand Down Expand Up @@ -253,7 +254,7 @@ pub(crate) fn run_tests(
rustdoc_options: &Arc<RustdocOptions>,
unused_extern_reports: &Arc<Mutex<Vec<UnusedExterns>>>,
mut standalone_tests: Vec<test::TestDescAndFn>,
mergeable_tests: FxHashMap<Edition, Vec<(DocTestBuilder, ScrapedDocTest)>>,
mergeable_tests: FxIndexMap<Edition, Vec<(DocTestBuilder, ScrapedDocTest)>>,
) {
let mut test_args = Vec::with_capacity(rustdoc_options.test_args.len() + 1);
test_args.insert(0, "rustdoctest".to_string());
Expand Down Expand Up @@ -775,7 +776,7 @@ pub(crate) trait DocTestVisitor {

struct CreateRunnableDocTests {
standalone_tests: Vec<test::TestDescAndFn>,
mergeable_tests: FxHashMap<Edition, Vec<(DocTestBuilder, ScrapedDocTest)>>,
mergeable_tests: FxIndexMap<Edition, Vec<(DocTestBuilder, ScrapedDocTest)>>,

rustdoc_options: Arc<RustdocOptions>,
opts: GlobalTestOptions,
Expand All @@ -790,7 +791,7 @@ impl CreateRunnableDocTests {
let can_merge_doctests = rustdoc_options.edition >= Edition::Edition2024;
CreateRunnableDocTests {
standalone_tests: Vec::new(),
mergeable_tests: FxHashMap::default(),
mergeable_tests: FxIndexMap::default(),
rustdoc_options: Arc::new(rustdoc_options),
opts,
visited_tests: FxHashMap::default(),
Expand Down
6 changes: 3 additions & 3 deletions src/librustdoc/doctest/runner.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::fmt::Write;

use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::fx::FxIndexSet;
use rustc_span::edition::Edition;

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

/// Convenient type to merge compatible doctests into one.
pub(crate) struct DocTestRunner {
crate_attrs: FxHashSet<String>,
crate_attrs: FxIndexSet<String>,
ids: String,
output: String,
supports_color: bool,
Expand All @@ -21,7 +21,7 @@ pub(crate) struct DocTestRunner {
impl DocTestRunner {
pub(crate) fn new() -> Self {
Self {
crate_attrs: FxHashSet::default(),
crate_attrs: FxIndexSet::default(),
ids: String::new(),
output: String::new(),
supports_color: true,
Expand Down
16 changes: 8 additions & 8 deletions src/librustdoc/formats/cache.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::mem;

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

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

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

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

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

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

/// All intra-doc links resolved so far.
///
Expand Down Expand Up @@ -376,7 +376,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
// Figure out the id of this impl. This may map to a
// primitive rather than always to a struct/enum.
// Note: matching twice to restrict the lifetime of the `i` borrow.
let mut dids = FxHashSet::default();
let mut dids = FxIndexSet::default();
match i.for_ {
clean::Type::Path { ref path }
| clean::BorrowedRef { type_: box clean::Type::Path { ref path }, .. } => {
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/html/highlight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use std::collections::VecDeque;
use std::fmt::{Display, Write};

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

#[derive(Eq, PartialEq, Clone, Copy)]
pub(crate) enum Tooltip {
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/html/highlight/tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use expect_test::expect_file;
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::fx::FxIndexMap;
use rustc_span::create_default_session_globals_then;

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

Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/html/layout.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::path::PathBuf;

use rinja::Template;
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::fx::FxIndexMap;

use super::static_files::{STATIC_FILES, StaticFiles};
use crate::externalfiles::ExternalHtml;
Expand All @@ -13,7 +13,7 @@ pub(crate) struct Layout {
pub(crate) logo: String,
pub(crate) favicon: String,
pub(crate) external_html: ExternalHtml,
pub(crate) default_settings: FxHashMap<String, String>,
pub(crate) default_settings: FxIndexMap<String, String>,
pub(crate) krate: String,
pub(crate) krate_version: String,
/// The given user css file which allow to customize the generated
Expand Down
8 changes: 4 additions & 4 deletions src/librustdoc/html/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use pulldown_cmark::{
BrokenLink, BrokenLinkCallback, CodeBlockKind, CowStr, Event, LinkType, OffsetIter, Options,
Parser, Tag, TagEnd, html,
};
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
use rustc_errors::{Diag, DiagMessage};
use rustc_hir::def_id::LocalDefId;
use rustc_middle::ty::TyCtxt;
Expand Down Expand Up @@ -651,12 +651,12 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for SummaryLine<'a, I> {
/// references.
struct Footnotes<'a, I> {
inner: I,
footnotes: FxHashMap<String, (Vec<Event<'a>>, u16)>,
footnotes: FxIndexMap<String, (Vec<Event<'a>>, u16)>,
}

impl<'a, I> Footnotes<'a, I> {
fn new(iter: I) -> Self {
Footnotes { inner: iter, footnotes: FxHashMap::default() }
Footnotes { inner: iter, footnotes: FxIndexMap::default() }
}

fn get_entry(&mut self, key: &str) -> &mut (Vec<Event<'a>>, u16) {
Expand Down Expand Up @@ -694,7 +694,7 @@ impl<'a, I: Iterator<Item = SpannedEvent<'a>>> Iterator for Footnotes<'a, I> {
Some(e) => return Some(e),
None => {
if !self.footnotes.is_empty() {
let mut v: Vec<_> = self.footnotes.drain().map(|(_, x)| x).collect();
let mut v: Vec<_> = self.footnotes.drain(..).map(|(_, x)| x).collect();
v.sort_by(|a, b| a.1.cmp(&b.1));
let mut ret = String::from("<div class=\"footnotes\"><hr><ol>");
for (mut content, id) in v {
Expand Down
14 changes: 7 additions & 7 deletions src/librustdoc/html/render/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::rc::Rc;
use std::sync::mpsc::{Receiver, channel};

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

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

/// Shared mutable state used in [`Context`] and elsewhere.
pub(crate) struct SharedContext<'tcx> {
Expand All @@ -90,7 +90,7 @@ pub(crate) struct SharedContext<'tcx> {
/// creation of the context (contains info like the favicon and added html).
pub(crate) layout: layout::Layout,
/// The local file sources we've emitted and their respective url-paths.
pub(crate) local_sources: FxHashMap<PathBuf, String>,
pub(crate) local_sources: FxIndexMap<PathBuf, String>,
/// Show the memory layout of types in the docs.
pub(super) show_type_layout: bool,
/// The base-URL of the issue tracker for when an item has been tagged with
Expand Down Expand Up @@ -567,7 +567,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
deref_id_map: Default::default(),
shared: Rc::new(scx),
include_sources,
types_with_notable_traits: FxHashSet::default(),
types_with_notable_traits: FxIndexSet::default(),
is_inside_inlined_module: false,
};

Expand All @@ -591,7 +591,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
id_map: IdMap::new(),
shared: Rc::clone(&self.shared),
include_sources: self.include_sources,
types_with_notable_traits: FxHashSet::default(),
types_with_notable_traits: FxIndexSet::default(),
is_inside_inlined_module: self.is_inside_inlined_module,
}
}
Expand Down
Loading

0 comments on commit 373971a

Please sign in to comment.