Handle librustdoc cases of rustc::potential_query_instability lint

This commit is contained in:
ismailarilik 2024-10-06 10:39:03 +03:00
parent 85e2f55d82
commit e0a20b484d
23 changed files with 114 additions and 115 deletions

View File

@ -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};
@ -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);

View File

@ -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;
@ -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 {
@ -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() {
@ -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};
@ -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(()) {
@ -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())

View File

@ -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,
@ -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

View File

@ -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::*;
@ -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,

View File

@ -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;
@ -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())
@ -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());
@ -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,
@ -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(),

View File

@ -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::{
@ -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,
@ -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,

View File

@ -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;
@ -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.
@ -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
@ -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.
///
@ -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 }, .. } => {

View File

@ -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;
@ -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 {

View File

@ -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};
@ -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)]);

View File

@ -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;
@ -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

View File

@ -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;
@ -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) {
@ -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 {

View File

@ -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;
@ -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> {
@ -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
@ -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,
};
@ -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,
}
}

View File

@ -47,7 +47,7 @@ use std::{fs, str};
use rinja::Template;
use rustc_attr::{ConstStability, DeprecatedSince, Deprecation, StabilityLevel, StableSince};
use rustc_data_structures::captures::Captures;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
use rustc_hir::Mutability;
use rustc_hir::def_id::{DefId, DefIdSet};
use rustc_middle::ty::print::PrintTraitRefExt;
@ -328,24 +328,24 @@ impl Ord for ItemEntry {
#[derive(Debug)]
struct AllTypes {
structs: FxHashSet<ItemEntry>,
enums: FxHashSet<ItemEntry>,
unions: FxHashSet<ItemEntry>,
primitives: FxHashSet<ItemEntry>,
traits: FxHashSet<ItemEntry>,
macros: FxHashSet<ItemEntry>,
functions: FxHashSet<ItemEntry>,
type_aliases: FxHashSet<ItemEntry>,
statics: FxHashSet<ItemEntry>,
constants: FxHashSet<ItemEntry>,
attribute_macros: FxHashSet<ItemEntry>,
derive_macros: FxHashSet<ItemEntry>,
trait_aliases: FxHashSet<ItemEntry>,
structs: FxIndexSet<ItemEntry>,
enums: FxIndexSet<ItemEntry>,
unions: FxIndexSet<ItemEntry>,
primitives: FxIndexSet<ItemEntry>,
traits: FxIndexSet<ItemEntry>,
macros: FxIndexSet<ItemEntry>,
functions: FxIndexSet<ItemEntry>,
type_aliases: FxIndexSet<ItemEntry>,
statics: FxIndexSet<ItemEntry>,
constants: FxIndexSet<ItemEntry>,
attribute_macros: FxIndexSet<ItemEntry>,
derive_macros: FxIndexSet<ItemEntry>,
trait_aliases: FxIndexSet<ItemEntry>,
}
impl AllTypes {
fn new() -> AllTypes {
let new_set = |cap| FxHashSet::with_capacity_and_hasher(cap, Default::default());
let new_set = |cap| FxIndexSet::with_capacity_and_hasher(cap, Default::default());
AllTypes {
structs: new_set(100),
enums: new_set(100),
@ -437,7 +437,7 @@ impl AllTypes {
}
fn print(self, f: &mut Buffer) {
fn print_entries(f: &mut Buffer, e: &FxHashSet<ItemEntry>, kind: ItemSection) {
fn print_entries(f: &mut Buffer, e: &FxIndexSet<ItemEntry>, kind: ItemSection) {
if !e.is_empty() {
let mut e: Vec<&ItemEntry> = e.iter().collect();
e.sort();
@ -1151,7 +1151,7 @@ fn render_attributes_in_code(w: &mut impl fmt::Write, it: &clean::Item, cx: &Con
#[derive(Copy, Clone)]
enum AssocItemLink<'a> {
Anchor(Option<&'a str>),
GotoSource(ItemId, &'a FxHashSet<Symbol>),
GotoSource(ItemId, &'a FxIndexSet<Symbol>),
}
impl<'a> AssocItemLink<'a> {
@ -1494,7 +1494,7 @@ fn notable_traits_decl(ty: &clean::Type, cx: &Context<'_>) -> (String, String) {
for it in &impl_.items {
if let clean::AssocTypeItem(ref tydef, ref _bounds) = it.kind {
out.push_str("<div class=\"where\"> ");
let empty_set = FxHashSet::default();
let empty_set = FxIndexSet::default();
let src_link = AssocItemLink::GotoSource(trait_did.into(), &empty_set);
assoc_type(
&mut out,
@ -2526,7 +2526,7 @@ fn render_call_locations<W: fmt::Write>(mut w: W, cx: &mut Context<'_>, item: &c
})()
.unwrap_or(DUMMY_SP);
let mut decoration_info = FxHashMap::default();
let mut decoration_info = FxIndexMap::default();
decoration_info.insert("highlight focus", vec![byte_ranges.remove(0)]);
decoration_info.insert("highlight", byte_ranges);

View File

@ -6,7 +6,7 @@ use std::rc::Rc;
use itertools::Itertools;
use rinja::Template;
use rustc_data_structures::captures::Captures;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::fx::{FxHashMap, FxIndexSet};
use rustc_hir as hir;
use rustc_hir::def::CtorKind;
use rustc_hir::def_id::DefId;
@ -932,7 +932,7 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
let cloned_shared = Rc::clone(&cx.shared);
let cache = &cloned_shared.cache;
let mut extern_crates = FxHashSet::default();
let mut extern_crates = FxIndexSet::default();
if !t.is_object_safe(cx.tcx()) {
write_section_heading(

View File

@ -774,7 +774,7 @@ pub(crate) fn get_function_type_for_search<'tcx>(
fn get_index_type(
clean_type: &clean::Type,
generics: Vec<RenderType>,
rgen: &mut FxHashMap<SimplifiedParam, (isize, Vec<RenderType>)>,
rgen: &mut FxIndexMap<SimplifiedParam, (isize, Vec<RenderType>)>,
) -> RenderType {
RenderType {
id: get_index_type_id(clean_type, rgen),
@ -785,7 +785,7 @@ fn get_index_type(
fn get_index_type_id(
clean_type: &clean::Type,
rgen: &mut FxHashMap<SimplifiedParam, (isize, Vec<RenderType>)>,
rgen: &mut FxIndexMap<SimplifiedParam, (isize, Vec<RenderType>)>,
) -> Option<RenderTypeId> {
use rustc_hir::def::{DefKind, Res};
match *clean_type {
@ -854,7 +854,7 @@ fn simplify_fn_type<'a, 'tcx>(
tcx: TyCtxt<'tcx>,
recurse: usize,
res: &mut Vec<RenderType>,
rgen: &mut FxHashMap<SimplifiedParam, (isize, Vec<RenderType>)>,
rgen: &mut FxIndexMap<SimplifiedParam, (isize, Vec<RenderType>)>,
is_return: bool,
cache: &Cache,
) {
@ -1198,7 +1198,7 @@ fn simplify_fn_constraint<'a, 'tcx>(
tcx: TyCtxt<'tcx>,
recurse: usize,
res: &mut Vec<(RenderTypeId, Vec<RenderType>)>,
rgen: &mut FxHashMap<SimplifiedParam, (isize, Vec<RenderType>)>,
rgen: &mut FxIndexMap<SimplifiedParam, (isize, Vec<RenderType>)>,
is_return: bool,
cache: &Cache,
) {
@ -1285,7 +1285,7 @@ fn get_fn_inputs_and_outputs<'tcx>(
) -> (Vec<RenderType>, Vec<RenderType>, Vec<Vec<RenderType>>) {
let decl = &func.decl;
let mut rgen: FxHashMap<SimplifiedParam, (isize, Vec<RenderType>)> = Default::default();
let mut rgen: FxIndexMap<SimplifiedParam, (isize, Vec<RenderType>)> = Default::default();
let combined_generics;
let (self_, generics) = if let Some((impl_self, impl_generics)) = impl_or_trait_generics {

View File

@ -1,6 +1,6 @@
use std::path::{Path, PathBuf};
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
use rustc_hir::intravisit::{self, Visitor};
@ -44,7 +44,7 @@ pub(crate) fn collect_spans_and_sources(
src_root: &Path,
include_sources: bool,
generate_link_to_definition: bool,
) -> (FxHashMap<PathBuf, String>, FxHashMap<Span, LinkFromSrc>) {
) -> (FxIndexMap<PathBuf, String>, FxHashMap<Span, LinkFromSrc>) {
let mut visitor = SpanMapVisitor { tcx, matches: FxHashMap::default() };
if include_sources {

View File

@ -28,7 +28,7 @@ use indexmap::IndexMap;
use itertools::Itertools;
use regex::Regex;
use rustc_data_structures::flock;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
use rustc_middle::ty::TyCtxt;
use rustc_middle::ty::fast_reject::DeepRejectCtxt;
use rustc_span::Symbol;
@ -505,8 +505,8 @@ createSrcSidebar();",
struct Hierarchy {
parent: Weak<Self>,
elem: OsString,
children: RefCell<FxHashMap<OsString, Rc<Self>>>,
elems: RefCell<FxHashSet<OsString>>,
children: RefCell<FxIndexMap<OsString, Rc<Self>>>,
elems: RefCell<FxIndexSet<OsString>>,
}
impl Hierarchy {
@ -961,8 +961,8 @@ impl Serialize for AliasSerializableImpl {
fn get_path_parts<T: CciPart>(
dst: &Path,
crates_info: &[CrateInfo],
) -> FxHashMap<PathBuf, Vec<String>> {
let mut templates: FxHashMap<PathBuf, Vec<String>> = FxHashMap::default();
) -> FxIndexMap<PathBuf, Vec<String>> {
let mut templates: FxIndexMap<PathBuf, Vec<String>> = FxIndexMap::default();
crates_info
.iter()
.map(|crate_info| T::from_crate_info(crate_info).parts.iter())

View File

@ -6,7 +6,7 @@ use std::rc::Rc;
use std::{fmt, fs};
use rinja::Template;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
use rustc_hir::def_id::LOCAL_CRATE;
use rustc_middle::ty::TyCtxt;
use rustc_session::Session;
@ -39,15 +39,15 @@ pub(crate) fn collect_local_sources<'tcx>(
tcx: TyCtxt<'tcx>,
src_root: &Path,
krate: &clean::Crate,
) -> FxHashMap<PathBuf, String> {
let mut lsc = LocalSourcesCollector { tcx, local_sources: FxHashMap::default(), src_root };
) -> FxIndexMap<PathBuf, String> {
let mut lsc = LocalSourcesCollector { tcx, local_sources: FxIndexMap::default(), src_root };
lsc.visit_crate(krate);
lsc.local_sources
}
struct LocalSourcesCollector<'a, 'tcx> {
tcx: TyCtxt<'tcx>,
local_sources: FxHashMap<PathBuf, String>,
local_sources: FxIndexMap<PathBuf, String>,
src_root: &'a Path,
}

View File

@ -20,7 +20,6 @@
#![warn(rustc::internal)]
#![allow(clippy::collapsible_if, clippy::collapsible_else_if)]
#![allow(rustc::diagnostic_outside_of_impl)]
#![allow(rustc::potential_query_instability)]
#![allow(rustc::untranslatable_diagnostic)]
extern crate thin_vec;
@ -99,7 +98,7 @@ use crate::clean::utils::DOC_RUST_LANG_ORG_CHANNEL;
/// Commas between elements are required (even if the expression is a block).
macro_rules! map {
($( $key: expr => $val: expr ),* $(,)*) => {{
let mut map = ::rustc_data_structures::fx::FxHashMap::default();
let mut map = ::rustc_data_structures::fx::FxIndexMap::default();
$( map.insert($key, $val); )*
map
}}

View File

@ -9,7 +9,7 @@ use std::ops::Range;
use pulldown_cmark::LinkType;
use rustc_ast::util::comments::may_have_doc_links;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet};
use rustc_data_structures::intern::Interned;
use rustc_errors::{Applicability, Diag, DiagMessage};
use rustc_hir::def::Namespace::*;
@ -778,9 +778,9 @@ fn trait_impls_for<'a>(
cx: &mut DocContext<'a>,
ty: Ty<'a>,
module: DefId,
) -> FxHashSet<(DefId, DefId)> {
) -> FxIndexSet<(DefId, DefId)> {
let tcx = cx.tcx;
let mut impls = FxHashSet::default();
let mut impls = FxIndexSet::default();
for &trait_ in tcx.doc_link_traits_in_scope(module) {
tcx.for_each_relevant_impl(trait_, ty, |impl_| {

View File

@ -219,7 +219,7 @@ pub(crate) fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) ->
panic!("collect-trait-impls can't run");
};
krate.external_traits.extend(cx.external_traits.drain());
krate.external_traits.extend(cx.external_traits.drain(..));
krate
}

View File

@ -3,7 +3,7 @@
use std::fs;
use std::path::PathBuf;
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::fx::FxIndexMap;
use rustc_errors::DiagCtxtHandle;
use rustc_hir::intravisit::{self, Visitor};
use rustc_hir::{self as hir};
@ -102,8 +102,8 @@ pub(crate) struct CallData {
pub(crate) is_bin: bool,
}
pub(crate) type FnCallLocations = FxHashMap<PathBuf, CallData>;
pub(crate) type AllCallLocations = FxHashMap<DefPathHash, FnCallLocations>;
pub(crate) type FnCallLocations = FxIndexMap<PathBuf, CallData>;
pub(crate) type AllCallLocations = FxIndexMap<DefPathHash, FnCallLocations>;
/// Visitor for traversing a crate and finding instances of function calls.
struct FindCalls<'a, 'tcx> {
@ -293,7 +293,7 @@ pub(crate) fn run(
debug!("Scrape examples target_crates: {target_crates:?}");
// Run call-finder on all items
let mut calls = FxHashMap::default();
let mut calls = FxIndexMap::default();
let mut finder =
FindCalls { calls: &mut calls, tcx, map: tcx.hir(), cx, target_crates, bin_crate };
tcx.hir().visit_all_item_likes_in_crate(&mut finder);
@ -332,7 +332,7 @@ pub(crate) fn load_call_locations(
with_examples: Vec<String>,
dcx: DiagCtxtHandle<'_>,
) -> AllCallLocations {
let mut all_calls: AllCallLocations = FxHashMap::default();
let mut all_calls: AllCallLocations = FxIndexMap::default();
for path in with_examples {
let bytes = match fs::read(&path) {
Ok(bytes) => bytes,

View File

@ -1,10 +1,9 @@
use std::collections::hash_map::Entry;
use std::fs;
use std::iter::Peekable;
use std::path::Path;
use std::str::Chars;
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::fx::{FxIndexMap, IndexEntry};
use rustc_errors::DiagCtxtHandle;
#[cfg(test)]
@ -12,8 +11,8 @@ mod tests;
#[derive(Debug)]
pub(crate) struct CssPath {
pub(crate) rules: FxHashMap<String, String>,
pub(crate) children: FxHashMap<String, CssPath>,
pub(crate) rules: FxIndexMap<String, String>,
pub(crate) children: FxIndexMap<String, CssPath>,
}
/// When encountering a `"` or a `'`, returns the whole string, including the quote characters.
@ -120,10 +119,10 @@ fn parse_rules(
content: &str,
selector: String,
iter: &mut Peekable<Chars<'_>>,
paths: &mut FxHashMap<String, CssPath>,
paths: &mut FxIndexMap<String, CssPath>,
) -> Result<(), String> {
let mut rules = FxHashMap::default();
let mut children = FxHashMap::default();
let mut rules = FxIndexMap::default();
let mut children = FxIndexMap::default();
loop {
// If the parent isn't a "normal" CSS selector, we only expect sub-selectors and not CSS
@ -146,10 +145,10 @@ fn parse_rules(
return Err(format!("Found empty value for rule `{rule}` in selector `{selector}`"));
}
match rules.entry(rule) {
Entry::Occupied(mut o) => {
IndexEntry::Occupied(mut o) => {
*o.get_mut() = value;
}
Entry::Vacant(v) => {
IndexEntry::Vacant(v) => {
v.insert(value);
}
}
@ -159,7 +158,7 @@ fn parse_rules(
}
match paths.entry(selector) {
Entry::Occupied(mut o) => {
IndexEntry::Occupied(mut o) => {
let v = o.get_mut();
for (key, value) in rules.into_iter() {
v.rules.insert(key, value);
@ -168,7 +167,7 @@ fn parse_rules(
v.children.insert(sel, child);
}
}
Entry::Vacant(v) => {
IndexEntry::Vacant(v) => {
v.insert(CssPath { rules, children });
}
}
@ -178,7 +177,7 @@ fn parse_rules(
pub(crate) fn parse_selectors(
content: &str,
iter: &mut Peekable<Chars<'_>>,
paths: &mut FxHashMap<String, CssPath>,
paths: &mut FxIndexMap<String, CssPath>,
) -> Result<(), String> {
let mut selector = String::new();
@ -202,17 +201,17 @@ pub(crate) fn parse_selectors(
/// The entry point to parse the CSS rules. Every time we encounter a `{`, we then parse the rules
/// inside it.
pub(crate) fn load_css_paths(content: &str) -> Result<FxHashMap<String, CssPath>, String> {
pub(crate) fn load_css_paths(content: &str) -> Result<FxIndexMap<String, CssPath>, String> {
let mut iter = content.chars().peekable();
let mut paths = FxHashMap::default();
let mut paths = FxIndexMap::default();
parse_selectors(content, &mut iter, &mut paths)?;
Ok(paths)
}
pub(crate) fn get_differences(
origin: &FxHashMap<String, CssPath>,
against: &FxHashMap<String, CssPath>,
origin: &FxIndexMap<String, CssPath>,
against: &FxIndexMap<String, CssPath>,
v: &mut Vec<String>,
) {
for (selector, entry) in origin.iter() {
@ -235,7 +234,7 @@ pub(crate) fn get_differences(
pub(crate) fn test_theme_against<P: AsRef<Path>>(
f: &P,
origin: &FxHashMap<String, CssPath>,
origin: &FxIndexMap<String, CssPath>,
dcx: DiagCtxtHandle<'_>,
) -> (bool, Vec<String>) {
let against = match fs::read_to_string(f)