diff --git a/compiler/rustc_borrowck/src/region_infer/dump_mir.rs b/compiler/rustc_borrowck/src/region_infer/dump_mir.rs index cfd3acb6bdebd..3ae58c6a7f28e 100644 --- a/compiler/rustc_borrowck/src/region_infer/dump_mir.rs +++ b/compiler/rustc_borrowck/src/region_infer/dump_mir.rs @@ -71,8 +71,8 @@ impl<'tcx> RegionInferenceContext<'tcx> { } } - let mut constraints: Vec<_> = self.constraints.outlives().iter().collect(); - constraints.sort(); + let constraints: Vec<_> = self.constraints.outlives().iter().collect(); + // constraints.sort(); for constraint in &constraints { let OutlivesConstraint { sup, sub, locations, category, variance_info: _ } = constraint; let (name, arg) = match locations { diff --git a/compiler/rustc_borrowck/src/region_infer/mod.rs b/compiler/rustc_borrowck/src/region_infer/mod.rs index b39a28f79aadd..683f4eb30ef93 100644 --- a/compiler/rustc_borrowck/src/region_infer/mod.rs +++ b/compiler/rustc_borrowck/src/region_infer/mod.rs @@ -611,8 +611,8 @@ impl<'tcx> RegionInferenceContext<'tcx> { #[instrument(skip(self, _body), level = "debug")] fn propagate_constraints(&mut self, _body: &Body<'tcx>) { debug!("constraints={:#?}", { - let mut constraints: Vec<_> = self.constraints.outlives().iter().collect(); - constraints.sort(); + let constraints: Vec<_> = self.constraints.outlives().iter().collect(); + // constraints.sort(); constraints .into_iter() .map(|c| (c, self.constraint_sccs.scc(c.sup), self.constraint_sccs.scc(c.sub))) diff --git a/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs b/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs index 32f18419753e9..d7cbe9affc465 100644 --- a/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs +++ b/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs @@ -319,7 +319,64 @@ fn add_unused_functions<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>) { continue; } - debug!("generating unused fn: {:?}", non_codegenned_def_id); - cx.define_unused_fn(non_codegenned_def_id); + if unused_def_ids_by_file.is_empty() { + // There are no unused functions with file names to add (in any CGU) + return; + } + + // Each `CodegenUnit` (CGU) has its own function_coverage_map, and generates a specific binary + // with its own coverage map. + // + // Each covered function `Instance` can be included in only one coverage map, produced from a + // specific function_coverage_map, from a specific CGU. + // + // Since unused functions did not generate code, they are not associated with any CGU yet. + // + // To avoid injecting the unused functions in multiple coverage maps (for multiple CGUs) + // determine which function_coverage_map has the responsibility for publishing unreachable + // coverage, based on file name: For each unused function, find the CGU that generates the + // first function (based on sorted `DefId`) from the same file. + // + // Add a new `FunctionCoverage` to the `function_coverage_map`, with unreachable code regions + // for each region in it's MIR. + + let mut first_covered_def_id_by_file: FxHashMap = FxHashMap::default(); + for &def_id in codegenned_def_ids.iter() { + if let Some(covered_file_name) = tcx.covered_file_name(def_id) { + // Only add files known to have unused functions + if unused_def_ids_by_file.contains_key(covered_file_name) { + first_covered_def_id_by_file.entry(*covered_file_name).or_insert(def_id); + } + } + } + + // Get the set of def_ids with coverage regions, known by *this* CoverageContext. + let cgu_covered_def_ids: DefIdSet = match cx.coverage_context() { + Some(ctx) => ctx + .function_coverage_map + .borrow() + .keys() + .map(|&instance| instance.def.def_id()) + .collect(), + None => return, + }; + + let cgu_covered_files: FxHashSet = + first_covered_def_id_by_file + .iter() + .filter_map(|(&file_name, def_id)| { + if cgu_covered_def_ids.contains(def_id) { Some(file_name) } else { None } + }) + .collect(); + + // For each file for which this CGU is responsible for adding unused function coverage, + // get the `def_id`s for each unused function (if any), define a synthetic function with a + // single LLVM coverage counter, and add the function's coverage `CodeRegion`s. to the + // function_coverage_map. + for covered_file_name in cgu_covered_files { + for def_id in unused_def_ids_by_file.remove(&covered_file_name).into_iter().flatten() { + cx.define_unused_fn(def_id); + } + } } } diff --git a/compiler/rustc_const_eval/src/transform/validate.rs b/compiler/rustc_const_eval/src/transform/validate.rs index 22ef0b2dda506..0d7fdd09f00c8 100644 --- a/compiler/rustc_const_eval/src/transform/validate.rs +++ b/compiler/rustc_const_eval/src/transform/validate.rs @@ -446,7 +446,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { } } let all_len = self.place_cache.len(); - self.place_cache.sort_unstable(); + self.place_cache.sort_by_key(|b| b.local); self.place_cache.dedup(); let has_duplicates = all_len != self.place_cache.len(); if has_duplicates { diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs index 266eec08cebf5..9d724567545eb 100644 --- a/compiler/rustc_infer/src/infer/mod.rs +++ b/compiler/rustc_infer/src/infer/mod.rs @@ -35,7 +35,6 @@ use rustc_span::symbol::Symbol; use rustc_span::Span; use std::cell::{Cell, Ref, RefCell}; -use std::collections::BTreeMap; use std::fmt; use self::combine::CombineFields; @@ -1500,7 +1499,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { span: Span, lbrct: LateBoundRegionConversionTime, value: ty::Binder<'tcx, T>, - ) -> (T, BTreeMap>) + ) -> (T, FxHashMap>) where T: TypeFoldable<'tcx>, { diff --git a/compiler/rustc_infer/src/infer/region_constraints/mod.rs b/compiler/rustc_infer/src/infer/region_constraints/mod.rs index 29775a9668531..94618747abec7 100644 --- a/compiler/rustc_infer/src/infer/region_constraints/mod.rs +++ b/compiler/rustc_infer/src/infer/region_constraints/mod.rs @@ -20,7 +20,6 @@ use rustc_middle::ty::{ReLateBound, ReVar}; use rustc_middle::ty::{Region, RegionVid}; use rustc_span::Span; -use std::collections::BTreeMap; use std::ops::Range; use std::{cmp, fmt, mem}; @@ -90,7 +89,7 @@ pub type VarInfos = IndexVec; pub struct RegionConstraintData<'tcx> { /// Constraints of the form `A <= B`, where either `A` or `B` can /// be a region variable (or neither, as it happens). - pub constraints: BTreeMap, SubregionOrigin<'tcx>>, + pub constraints: FxHashMap, SubregionOrigin<'tcx>>, /// Constraints of the form `R0 member of [R1, ..., Rn]`, meaning that /// `R0` must be equal to one of the regions `R1..Rn`. These occur @@ -127,7 +126,7 @@ pub struct RegionConstraintData<'tcx> { } /// Represents a constraint that influences the inference process. -#[derive(Clone, Copy, PartialEq, Eq, Debug, PartialOrd, Ord)] +#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)] pub enum Constraint<'tcx> { /// A region variable is a subregion of another. VarSubVar(RegionVid, RegionVid), diff --git a/compiler/rustc_middle/Cargo.toml b/compiler/rustc_middle/Cargo.toml index 30664784ed8f8..b1334410237e7 100644 --- a/compiler/rustc_middle/Cargo.toml +++ b/compiler/rustc_middle/Cargo.toml @@ -29,7 +29,7 @@ rustc_index = { path = "../rustc_index" } rustc_serialize = { path = "../rustc_serialize" } rustc_ast = { path = "../rustc_ast" } rustc_span = { path = "../rustc_span" } -chalk-ir = "0.75.0" +chalk-ir = "0.76.0" smallvec = { version = "1.6.1", features = ["union", "may_dangle"] } rustc_session = { path = "../rustc_session" } rustc_type_ir = { path = "../rustc_type_ir" } diff --git a/compiler/rustc_middle/src/lib.rs b/compiler/rustc_middle/src/lib.rs index 920eca7a71772..da4002cf1a206 100644 --- a/compiler/rustc_middle/src/lib.rs +++ b/compiler/rustc_middle/src/lib.rs @@ -36,6 +36,7 @@ #![feature(get_mut_unchecked)] #![feature(if_let_guard)] #![feature(map_first_last)] +#![feature(negative_impls)] #![feature(never_type)] #![feature(extern_types)] #![feature(new_uninit)] diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index 48f39b26152cb..7b8592d0c05fb 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -1841,7 +1841,7 @@ rustc_index::newtype_index! { } } -#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub struct PlaceRef<'tcx> { pub local: Local, pub projection: &'tcx [PlaceElem<'tcx>], diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index 5dc7b21964266..dc527df948cce 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -1089,7 +1089,7 @@ rustc_queries! { } /// Return all `impl` blocks in the current crate. - query all_local_trait_impls(_: ()) -> &'tcx BTreeMap> { + query all_local_trait_impls(_: ()) -> &'tcx FxHashMap> { desc { "local trait impls" } } diff --git a/compiler/rustc_middle/src/ty/adt.rs b/compiler/rustc_middle/src/ty/adt.rs index 6cec75d36e2c2..a28318fe992d6 100644 --- a/compiler/rustc_middle/src/ty/adt.rs +++ b/compiler/rustc_middle/src/ty/adt.rs @@ -17,7 +17,6 @@ use rustc_span::symbol::sym; use rustc_target::abi::VariantIdx; use std::cell::RefCell; -use std::cmp::Ordering; use std::hash::{Hash, Hasher}; use std::ops::Range; use std::str; @@ -100,20 +99,6 @@ pub struct AdtDef { pub repr: ReprOptions, } -impl PartialOrd for AdtDef { - fn partial_cmp(&self, other: &AdtDef) -> Option { - Some(self.cmp(&other)) - } -} - -/// There should be only one AdtDef for each `did`, therefore -/// it is fine to implement `Ord` only based on `did`. -impl Ord for AdtDef { - fn cmp(&self, other: &AdtDef) -> Ordering { - self.did.cmp(&other.did) - } -} - /// There should be only one AdtDef for each `did`, therefore /// it is fine to implement `PartialEq` only based on `did`. impl PartialEq for AdtDef { diff --git a/compiler/rustc_middle/src/ty/consts.rs b/compiler/rustc_middle/src/ty/consts.rs index d6c35dfef8888..48c00eef13e61 100644 --- a/compiler/rustc_middle/src/ty/consts.rs +++ b/compiler/rustc_middle/src/ty/consts.rs @@ -18,7 +18,7 @@ pub use kind::*; pub use valtree::*; /// Typed constant value. -#[derive(Copy, Clone, Debug, Hash, TyEncodable, TyDecodable, Eq, PartialEq, Ord, PartialOrd)] +#[derive(Copy, Clone, Debug, Hash, TyEncodable, TyDecodable, Eq, PartialEq)] #[derive(HashStable)] pub struct Const<'tcx> { pub ty: Ty<'tcx>, diff --git a/compiler/rustc_middle/src/ty/consts/kind.rs b/compiler/rustc_middle/src/ty/consts/kind.rs index af7c2c5cb4cff..24ba589f27ab5 100644 --- a/compiler/rustc_middle/src/ty/consts/kind.rs +++ b/compiler/rustc_middle/src/ty/consts/kind.rs @@ -12,7 +12,7 @@ use rustc_target::abi::Size; use super::ScalarInt; /// An unevaluated, potentially generic, constant. -#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, TyEncodable, TyDecodable, Lift)] +#[derive(Copy, Clone, Debug, Eq, PartialEq, TyEncodable, TyDecodable, Lift)] #[derive(Hash, HashStable)] pub struct Unevaluated<'tcx, P = Option> { pub def: ty::WithOptConstParam, @@ -43,7 +43,7 @@ impl<'tcx, P: Default> Unevaluated<'tcx, P> { } /// Represents a constant in Rust. -#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, TyEncodable, TyDecodable)] +#[derive(Copy, Clone, Debug, Eq, PartialEq, TyEncodable, TyDecodable)] #[derive(Hash, HashStable)] pub enum ConstKind<'tcx> { /// A const generic parameter. diff --git a/compiler/rustc_middle/src/ty/fold.rs b/compiler/rustc_middle/src/ty/fold.rs index 3133cdfdd7a72..1382c265bbcf3 100644 --- a/compiler/rustc_middle/src/ty/fold.rs +++ b/compiler/rustc_middle/src/ty/fold.rs @@ -35,9 +35,8 @@ use crate::ty::{self, flags::FlagComputation, Binder, Ty, TyCtxt, TypeFlags}; use rustc_hir as hir; use rustc_hir::def_id::DefId; -use rustc_data_structures::fx::FxHashSet; +use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::sso::SsoHashSet; -use std::collections::BTreeMap; use std::fmt; use std::ops::ControlFlow; @@ -695,12 +694,12 @@ impl<'tcx> TyCtxt<'tcx> { self, value: Binder<'tcx, T>, mut fld_r: F, - ) -> (T, BTreeMap>) + ) -> (T, FxHashMap>) where F: FnMut(ty::BoundRegion) -> ty::Region<'tcx>, T: TypeFoldable<'tcx>, { - let mut region_map = BTreeMap::new(); + let mut region_map = FxHashMap::default(); let mut real_fld_r = |br: ty::BoundRegion| *region_map.entry(br).or_insert_with(|| fld_r(br)); let value = value.skip_binder(); @@ -747,14 +746,14 @@ impl<'tcx> TyCtxt<'tcx> { mut fld_r: F, fld_t: G, fld_c: H, - ) -> (T, BTreeMap>) + ) -> (T, FxHashMap>) where F: FnMut(ty::BoundRegion) -> ty::Region<'tcx>, G: FnMut(ty::BoundTy) -> Ty<'tcx>, H: FnMut(ty::BoundVar, Ty<'tcx>) -> &'tcx ty::Const<'tcx>, T: TypeFoldable<'tcx>, { - let mut region_map = BTreeMap::new(); + let mut region_map = FxHashMap::default(); let real_fld_r = |br: ty::BoundRegion| *region_map.entry(br).or_insert_with(|| fld_r(br)); let value = self.replace_escaping_bound_vars(value.skip_binder(), real_fld_r, fld_t, fld_c); (value, region_map) diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 4bc3e23f4a588..db719f9ea2101 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -42,8 +42,6 @@ use rustc_span::symbol::{kw, Ident, Symbol}; use rustc_span::{sym, Span}; use rustc_target::abi::Align; -use std::cmp::Ordering; -use std::collections::BTreeMap; use std::hash::{Hash, Hasher}; use std::ops::ControlFlow; use std::{fmt, ptr, str}; @@ -134,7 +132,7 @@ pub struct ResolverOutputs { /// via `extern crate` item and not `--extern` option or compiler built-in. pub extern_prelude: FxHashMap, pub main_def: Option, - pub trait_impls: BTreeMap>, + pub trait_impls: FxHashMap>, /// A list of proc macro LocalDefIds, written out in the order in which /// they are declared in the static array generated by proc_macro_harness. pub proc_macros: Vec, @@ -421,18 +419,6 @@ impl<'tcx> TyS<'tcx> { #[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))] static_assert_size!(TyS<'_>, 40); -impl<'tcx> Ord for TyS<'tcx> { - fn cmp(&self, other: &TyS<'tcx>) -> Ordering { - self.kind().cmp(other.kind()) - } -} - -impl<'tcx> PartialOrd for TyS<'tcx> { - fn partial_cmp(&self, other: &TyS<'tcx>) -> Option { - Some(self.kind().cmp(other.kind())) - } -} - impl<'tcx> PartialEq for TyS<'tcx> { #[inline] fn eq(&self, other: &TyS<'tcx>) -> bool { @@ -1101,7 +1087,7 @@ pub type PlaceholderRegion = Placeholder; pub type PlaceholderType = Placeholder; #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, HashStable)] -#[derive(TyEncodable, TyDecodable, PartialOrd, Ord)] +#[derive(TyEncodable, TyDecodable)] pub struct BoundConst<'tcx> { pub var: BoundVar, pub ty: Ty<'tcx>, @@ -1161,7 +1147,7 @@ pub type PlaceholderConst<'tcx> = Placeholder>; /// Meaning that we need to use `type_of(const_param_did)` if `const_param_did` is `Some` /// to get the type of `did`. #[derive(Copy, Clone, Debug, TypeFoldable, Lift, TyEncodable, TyDecodable)] -#[derive(PartialEq, Eq, PartialOrd, Ord)] +#[derive(PartialEq, Eq)] #[derive(Hash, HashStable)] pub struct WithOptConstParam { pub did: T, diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index bbdaf248a9e72..eb0cc31ebb0a5 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -2,7 +2,7 @@ use crate::mir::interpret::{AllocRange, ConstValue, GlobalAlloc, Pointer, Proven use crate::ty::subst::{GenericArg, GenericArgKind, Subst}; use crate::ty::{self, ConstInt, DefIdTree, ParamConst, ScalarInt, Term, Ty, TyCtxt, TypeFoldable}; use rustc_apfloat::ieee::{Double, Single}; -use rustc_data_structures::fx::FxHashMap; +use rustc_data_structures::fx::{FxHashMap, FxIndexMap}; use rustc_data_structures::sso::SsoHashSet; use rustc_hir as hir; use rustc_hir::def::{self, CtorKind, DefKind, Namespace}; @@ -17,7 +17,6 @@ use rustc_target::spec::abi::Abi; use std::cell::Cell; use std::char; -use std::collections::BTreeMap; use std::convert::TryFrom; use std::fmt::{self, Write as _}; use std::iter; @@ -774,8 +773,8 @@ pub trait PrettyPrinter<'tcx>: // by looking up the projections associated with the def_id. let bounds = self.tcx().explicit_item_bounds(def_id); - let mut traits = BTreeMap::new(); - let mut fn_traits = BTreeMap::new(); + let mut traits = FxHashMap::default(); + let mut fn_traits = FxHashMap::default(); let mut is_sized = false; for (predicate, _) in bounds { @@ -951,11 +950,11 @@ pub trait PrettyPrinter<'tcx>: &mut self, trait_ref: ty::PolyTraitRef<'tcx>, proj_ty: Option<(DefId, ty::Binder<'tcx, Term<'tcx>>)>, - traits: &mut BTreeMap< + traits: &mut FxIndexMap< ty::PolyTraitRef<'tcx>, - BTreeMap>>, + FxIndexMap>>, >, - fn_traits: &mut BTreeMap, OpaqueFnEntry<'tcx>>, + fn_traits: &mut FxIndexMap, OpaqueFnEntry<'tcx>>, ) { let trait_def_id = trait_ref.def_id(); @@ -1098,7 +1097,7 @@ pub trait PrettyPrinter<'tcx>: // // To avoid that causing instabilities in compiletest // output, sort the auto-traits alphabetically. - auto_traits.sort(); + auto_traits.sort_by_key(|t| t.clone().0); for (_, def_id) in auto_traits { if !first { @@ -2024,7 +2023,7 @@ impl FmtPrinter<'_, '_, F> { struct RegionFolder<'a, 'tcx> { tcx: TyCtxt<'tcx>, current_index: ty::DebruijnIndex, - region_map: BTreeMap>, + region_map: FxHashMap>, name: &'a mut (dyn FnMut(ty::BoundRegion) -> ty::Region<'tcx> + 'a), } @@ -2086,7 +2085,7 @@ impl<'tcx, F: fmt::Write> FmtPrinter<'_, 'tcx, F> { pub fn name_all_regions( mut self, value: &ty::Binder<'tcx, T>, - ) -> Result<(Self, T, BTreeMap>), fmt::Error> + ) -> Result<(Self, T, FxHashMap>), fmt::Error> where T: Print<'tcx, Self, Output = Self, Error = fmt::Error> + TypeFoldable<'tcx>, { @@ -2130,7 +2129,7 @@ impl<'tcx, F: fmt::Write> FmtPrinter<'_, 'tcx, F> { // anyways. let (new_value, map) = if self.tcx().sess.verbose() { // anon index + 1 (BrEnv takes 0) -> name - let mut region_map: BTreeMap = BTreeMap::default(); + let mut region_map: FxHashMap = FxHashMap::default(); let bound_vars = value.bound_vars(); for var in bound_vars { match var { @@ -2211,7 +2210,7 @@ impl<'tcx, F: fmt::Write> FmtPrinter<'_, 'tcx, F> { tcx, current_index: ty::INNERMOST, name: &mut name, - region_map: BTreeMap::new(), + region_map: FxHashMap::default(), }; let new_value = value.clone().skip_binder().fold_with(&mut folder); let region_map = folder.region_map; diff --git a/compiler/rustc_middle/src/ty/query.rs b/compiler/rustc_middle/src/ty/query.rs index 4a38d1c422f92..040e642b7b6d6 100644 --- a/compiler/rustc_middle/src/ty/query.rs +++ b/compiler/rustc_middle/src/ty/query.rs @@ -56,7 +56,6 @@ use rustc_ast as ast; use rustc_attr as attr; use rustc_span::symbol::Symbol; use rustc_span::{Span, DUMMY_SP}; -use std::collections::BTreeMap; use std::ops::Deref; use std::path::PathBuf; use std::sync::Arc; diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index 20db25f7899dd..638cf24f49ecb 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -25,14 +25,14 @@ use std::marker::PhantomData; use std::ops::Range; use ty::util::IntTypeExt; -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, TyEncodable, TyDecodable)] +#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, TyEncodable, TyDecodable)] #[derive(HashStable, TypeFoldable, Lift)] pub struct TypeAndMut<'tcx> { pub ty: Ty<'tcx>, pub mutbl: hir::Mutability, } -#[derive(Clone, PartialEq, PartialOrd, Eq, Ord, Hash, TyEncodable, TyDecodable, Copy)] +#[derive(Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable, Copy)] #[derive(HashStable)] /// A "free" region `fr` can be interpreted as "some region /// at least as big as the scope `fr.scope`". @@ -41,7 +41,7 @@ pub struct FreeRegion { pub bound_region: BoundRegionKind, } -#[derive(Clone, PartialEq, PartialOrd, Eq, Ord, Hash, TyEncodable, TyDecodable, Copy)] +#[derive(Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable, Copy)] #[derive(HashStable)] pub enum BoundRegionKind { /// An anonymous region parameter for a given fn (&T) @@ -58,7 +58,7 @@ pub enum BoundRegionKind { BrEnv, } -#[derive(Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable, Debug, PartialOrd, Ord)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable, Debug)] #[derive(HashStable)] pub struct BoundRegion { pub var: BoundVar, @@ -78,7 +78,7 @@ impl BoundRegionKind { /// /// N.B., if you change this, you'll probably want to change the corresponding /// AST structure in `rustc_ast/src/ast.rs` as well. -#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, TyDecodable, Debug)] +#[derive(Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable, Debug)] #[derive(HashStable)] #[rustc_diagnostic_item = "TyKind"] pub enum TyKind<'tcx> { @@ -765,7 +765,7 @@ impl<'tcx> InlineConstSubsts<'tcx> { } } -#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Ord, Eq, Hash, TyEncodable, TyDecodable)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable)] #[derive(HashStable, TypeFoldable)] pub enum ExistentialPredicate<'tcx> { /// E.g., `Iterator`. @@ -891,7 +891,7 @@ impl<'tcx> List>> { /// /// Trait references also appear in object types like `Foo`, but in /// that case the `Self` parameter is absent from the substitutions. -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, TyDecodable)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable)] #[derive(HashStable, TypeFoldable)] pub struct TraitRef<'tcx> { pub def_id: DefId, @@ -955,7 +955,7 @@ impl<'tcx> PolyTraitRef<'tcx> { /// /// The substitutions don't include the erased `Self`, only trait /// type and lifetime parameters (`[X, Y]` and `['a, 'b]` above). -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, TyDecodable)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable)] #[derive(HashStable, TypeFoldable)] pub struct ExistentialTraitRef<'tcx> { pub def_id: DefId, @@ -1004,7 +1004,7 @@ impl<'tcx> PolyExistentialTraitRef<'tcx> { } } -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, TyEncodable, TyDecodable)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, TyEncodable, TyDecodable)] #[derive(HashStable)] pub enum BoundVariableKind { Ty(BoundTyKind), @@ -1021,7 +1021,7 @@ pub enum BoundVariableKind { /// e.g., `liberate_late_bound_regions`). /// /// `Decodable` and `Encodable` are implemented for `Binder` using the `impl_binder_encode_decode!` macro. -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] pub struct Binder<'tcx, T>(T, &'tcx List); impl<'tcx, T> Binder<'tcx, T> @@ -1175,7 +1175,7 @@ impl<'tcx, T> Binder<'tcx, Option> { /// Represents the projection of an associated type. In explicit UFCS /// form this would be written `>::N`. -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, TyEncodable, TyDecodable)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, TyEncodable, TyDecodable)] #[derive(HashStable, TypeFoldable)] pub struct ProjectionTy<'tcx> { /// The parameters of the associated item. @@ -1240,7 +1240,7 @@ pub type PolyGenSig<'tcx> = Binder<'tcx, GenSig<'tcx>>; /// - `inputs`: is the list of arguments and their modes. /// - `output`: is the return type. /// - `c_variadic`: indicates whether this is a C-variadic function. -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, TyDecodable)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable)] #[derive(HashStable, TypeFoldable)] pub struct FnSig<'tcx> { pub inputs_and_output: &'tcx List>, @@ -1445,7 +1445,7 @@ pub type Region<'tcx> = &'tcx RegionKind; /// [1]: https://smallcultfollowing.com/babysteps/blog/2013/10/29/intermingled-parameter-lists/ /// [2]: https://smallcultfollowing.com/babysteps/blog/2013/11/04/intermingled-parameter-lists/ /// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/traits/hrtb.html -#[derive(Clone, PartialEq, Eq, Hash, Copy, TyEncodable, TyDecodable, PartialOrd, Ord)] +#[derive(Clone, PartialEq, Eq, Hash, Copy, TyEncodable, TyDecodable)] pub enum RegionKind { /// Region bound in a type or fn declaration which will be /// substituted 'early' -- that is, at the same time when type @@ -1483,7 +1483,7 @@ pub enum RegionKind { ReErased, } -#[derive(Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable, Debug, PartialOrd, Ord)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable, Debug)] pub struct EarlyBoundRegion { pub def_id: DefId, pub index: u32, @@ -1535,7 +1535,7 @@ impl From for BoundTy { } /// A `ProjectionPredicate` for an `ExistentialTraitRef`. -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, TyEncodable, TyDecodable)] +#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, TyEncodable, TyDecodable)] #[derive(HashStable, TypeFoldable)] pub struct ExistentialProjection<'tcx> { pub item_def_id: DefId, @@ -2279,7 +2279,7 @@ impl<'tcx> TyS<'tcx> { /// a miscompilation or unsoundness. /// /// When in doubt, use `VarianceDiagInfo::default()` -#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)] pub enum VarianceDiagInfo<'tcx> { /// No additional information - this is the default. /// We will not add any additional information to error messages. diff --git a/compiler/rustc_middle/src/ty/subst.rs b/compiler/rustc_middle/src/ty/subst.rs index ab33fbcca15a3..2f44b7e8eafba 100644 --- a/compiler/rustc_middle/src/ty/subst.rs +++ b/compiler/rustc_middle/src/ty/subst.rs @@ -13,7 +13,6 @@ use rustc_span::{Span, DUMMY_SP}; use smallvec::SmallVec; use core::intrinsics; -use std::cmp::Ordering; use std::fmt; use std::marker::PhantomData; use std::mem; @@ -36,7 +35,7 @@ const TYPE_TAG: usize = 0b00; const REGION_TAG: usize = 0b01; const CONST_TAG: usize = 0b10; -#[derive(Debug, TyEncodable, TyDecodable, PartialEq, Eq, PartialOrd, Ord, HashStable)] +#[derive(Debug, TyEncodable, TyDecodable, PartialEq, Eq, HashStable)] pub enum GenericArgKind<'tcx> { Lifetime(ty::Region<'tcx>), Type(Ty<'tcx>), @@ -77,18 +76,6 @@ impl<'tcx> fmt::Debug for GenericArg<'tcx> { } } -impl<'tcx> Ord for GenericArg<'tcx> { - fn cmp(&self, other: &GenericArg<'_>) -> Ordering { - self.unpack().cmp(&other.unpack()) - } -} - -impl<'tcx> PartialOrd for GenericArg<'tcx> { - fn partial_cmp(&self, other: &GenericArg<'_>) -> Option { - Some(self.cmp(&other)) - } -} - impl<'tcx> From> for GenericArg<'tcx> { fn from(r: ty::Region<'tcx>) -> GenericArg<'tcx> { GenericArgKind::Lifetime(r).pack() diff --git a/compiler/rustc_mir_build/src/build/matches/mod.rs b/compiler/rustc_mir_build/src/build/matches/mod.rs index e3a05e01ea8f0..f39a1beb3f170 100644 --- a/compiler/rustc_mir_build/src/build/matches/mod.rs +++ b/compiler/rustc_mir_build/src/build/matches/mod.rs @@ -1724,7 +1724,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } // Deduplicate and ensure a deterministic order. - all_fake_borrows.sort(); + all_fake_borrows.sort_by_key(|b| b.local); all_fake_borrows.dedup(); debug!("add_fake_borrows all_fake_borrows = {:?}", all_fake_borrows); diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index f5b2ba8fd72eb..40013f4b127c9 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -67,7 +67,7 @@ use rustc_span::{Span, DUMMY_SP}; use smallvec::{smallvec, SmallVec}; use std::cell::{Cell, RefCell}; -use std::collections::{BTreeMap, BTreeSet}; +use std::collections::BTreeSet; use std::ops::ControlFlow; use std::{cmp, fmt, iter, mem, ptr}; use tracing::debug; @@ -1059,7 +1059,7 @@ pub struct Resolver<'a> { item_generics_num_lifetimes: FxHashMap, main_def: Option, - trait_impls: BTreeMap>, + trait_impls: FxHashMap>, /// A list of proc macro LocalDefIds, written out in the order in which /// they are declared in the static array generated by proc_macro_harness. proc_macros: Vec, diff --git a/compiler/rustc_span/src/def_id.rs b/compiler/rustc_span/src/def_id.rs index 5390eed89fadc..5b97408b36220 100644 --- a/compiler/rustc_span/src/def_id.rs +++ b/compiler/rustc_span/src/def_id.rs @@ -218,7 +218,7 @@ impl Decodable for DefIndex { /// index and a def index. /// /// You can create a `DefId` from a `LocalDefId` using `local_def_id.to_def_id()`. -#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Copy)] +#[derive(Clone, PartialEq, Eq, Copy)] // On below-64 bit systems we can simply use the derived `Hash` impl #[cfg_attr(not(target_pointer_width = "64"), derive(Hash))] #[repr(C)] @@ -234,6 +234,12 @@ pub struct DefId { pub index: DefIndex, } +// To ensure correctness of incremental compilation, +// `DefId` must not implement `Ord` or `PartialOrd`. +// See https://github.com/rust-lang/rust/issues/90317. +impl !Ord for DefId {} +impl !PartialOrd for DefId {} + // On 64-bit systems, we can hash the whole `DefId` as one `u64` instead of two `u32`s. This // improves performance without impairing `FxHash` quality. So the below code gets compiled to a // noop on little endian systems because the memory layout of `DefId` is as follows: diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs index 0760f62685127..713f3271d40d5 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -12,6 +12,7 @@ use crate::infer::error_reporting::{TyCategory, TypeAnnotationNeeded as ErrorCod use crate::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use crate::infer::{self, InferCtxt, TyCtxtInferExt}; use rustc_data_structures::fx::FxHashMap; +use rustc_data_structures::stable_set::FxHashSet; use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder, ErrorReported}; use rustc_hir as hir; use rustc_hir::def_id::DefId; @@ -1570,7 +1571,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> { self.tcx.find_map_relevant_impl(trait_def_id, trait_ref.skip_binder().self_ty(), Some) }; let required_trait_path = self.tcx.def_path_str(trait_ref.def_id()); - let traits_with_same_path: std::collections::BTreeSet<_> = self + let traits_with_same_path: FxHashSet<_> = self .tcx .all_traits() .filter(|trait_def_id| *trait_def_id != trait_ref.def_id()) diff --git a/compiler/rustc_trait_selection/src/traits/project.rs b/compiler/rustc_trait_selection/src/traits/project.rs index f49f53351aac8..1fa1f099ee98d 100644 --- a/compiler/rustc_trait_selection/src/traits/project.rs +++ b/compiler/rustc_trait_selection/src/traits/project.rs @@ -19,6 +19,7 @@ use super::{Normalized, NormalizedTy, ProjectionCacheEntry, ProjectionCacheKey}; use crate::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use crate::infer::{InferCtxt, InferOk, LateBoundRegionConversionTime}; use crate::traits::error_reporting::InferCtxtExt as _; +use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::sso::SsoHashSet; use rustc_data_structures::stack::ensure_sufficient_stack; use rustc_errors::ErrorReported; @@ -30,8 +31,6 @@ use rustc_middle::ty::subst::Subst; use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt}; use rustc_span::symbol::sym; -use std::collections::BTreeMap; - pub use rustc_middle::traits::Reveal; pub type PolyProjectionObligation<'tcx> = Obligation<'tcx, ty::PolyProjectionPredicate<'tcx>>; @@ -512,9 +511,9 @@ pub struct BoundVarReplacer<'me, 'tcx> { // These three maps track the bound variable that were replaced by placeholders. It might be // nice to remove these since we already have the `kind` in the placeholder; we really just need // the `var` (but we *could* bring that into scope if we were to track them as we pass them). - mapped_regions: BTreeMap, - mapped_types: BTreeMap, - mapped_consts: BTreeMap, ty::BoundVar>, + mapped_regions: FxHashMap, + mapped_types: FxHashMap, + mapped_consts: FxHashMap, ty::BoundVar>, // The current depth relative to *this* folding, *not* the entire normalization. In other words, // the depth of binders we've passed here. current_index: ty::DebruijnIndex, @@ -532,13 +531,15 @@ impl<'me, 'tcx> BoundVarReplacer<'me, 'tcx> { value: T, ) -> ( T, - BTreeMap, - BTreeMap, - BTreeMap, ty::BoundVar>, + FxHashMap, + FxHashMap, + FxHashMap, ty::BoundVar>, ) { - let mapped_regions: BTreeMap = BTreeMap::new(); - let mapped_types: BTreeMap = BTreeMap::new(); - let mapped_consts: BTreeMap, ty::BoundVar> = BTreeMap::new(); + let mapped_regions: FxHashMap = + FxHashMap::default(); + let mapped_types: FxHashMap = FxHashMap::default(); + let mapped_consts: FxHashMap, ty::BoundVar> = + FxHashMap::default(); let mut replacer = BoundVarReplacer { infcx, @@ -648,9 +649,9 @@ impl<'tcx> TypeFolder<'tcx> for BoundVarReplacer<'_, 'tcx> { // The inverse of `BoundVarReplacer`: replaces placeholders with the bound vars from which they came. pub struct PlaceholderReplacer<'me, 'tcx> { infcx: &'me InferCtxt<'me, 'tcx>, - mapped_regions: BTreeMap, - mapped_types: BTreeMap, - mapped_consts: BTreeMap, ty::BoundVar>, + mapped_regions: FxHashMap, + mapped_types: FxHashMap, + mapped_consts: FxHashMap, ty::BoundVar>, universe_indices: &'me Vec>, current_index: ty::DebruijnIndex, } @@ -658,9 +659,9 @@ pub struct PlaceholderReplacer<'me, 'tcx> { impl<'me, 'tcx> PlaceholderReplacer<'me, 'tcx> { pub fn replace_placeholders>( infcx: &'me InferCtxt<'me, 'tcx>, - mapped_regions: BTreeMap, - mapped_types: BTreeMap, - mapped_consts: BTreeMap, ty::BoundVar>, + mapped_regions: FxHashMap, + mapped_types: FxHashMap, + mapped_consts: FxHashMap, ty::BoundVar>, universe_indices: &'me Vec>, value: T, ) -> T { diff --git a/compiler/rustc_traits/src/chalk/lowering.rs b/compiler/rustc_traits/src/chalk/lowering.rs index 67d0ba39667d3..3fc854dc82c0d 100644 --- a/compiler/rustc_traits/src/chalk/lowering.rs +++ b/compiler/rustc_traits/src/chalk/lowering.rs @@ -32,6 +32,7 @@ //! variables from the current `Binder`. use rustc_ast::ast; +use rustc_data_structures::fx::FxIndexMap; use rustc_middle::traits::{ChalkEnvironmentAndGoal, ChalkRustInterner as RustInterner}; use rustc_middle::ty::fold::TypeFolder; use rustc_middle::ty::subst::{GenericArg, GenericArgKind, SubstsRef}; @@ -819,11 +820,11 @@ crate fn collect_bound_vars<'tcx, T: TypeFoldable<'tcx>>( interner: RustInterner<'tcx>, tcx: TyCtxt<'tcx>, ty: Binder<'tcx, T>, -) -> (T, chalk_ir::VariableKinds>, BTreeMap) { +) -> (T, chalk_ir::VariableKinds>, FxIndexMap) { let mut bound_vars_collector = BoundVarsCollector::new(); ty.as_ref().skip_binder().visit_with(&mut bound_vars_collector); let mut parameters = bound_vars_collector.parameters; - let named_parameters: BTreeMap = bound_vars_collector + let named_parameters: FxIndexMap = bound_vars_collector .named_parameters .into_iter() .enumerate() @@ -937,11 +938,11 @@ impl<'tcx> TypeVisitor<'tcx> for BoundVarsCollector<'tcx> { struct NamedBoundVarSubstitutor<'a, 'tcx> { tcx: TyCtxt<'tcx>, binder_index: ty::DebruijnIndex, - named_parameters: &'a BTreeMap, + named_parameters: &'a FxIndexMap, } impl<'a, 'tcx> NamedBoundVarSubstitutor<'a, 'tcx> { - fn new(tcx: TyCtxt<'tcx>, named_parameters: &'a BTreeMap) -> Self { + fn new(tcx: TyCtxt<'tcx>, named_parameters: &'a FxIndexMap) -> Self { NamedBoundVarSubstitutor { tcx, binder_index: ty::INNERMOST, named_parameters } } } @@ -985,8 +986,8 @@ crate struct ParamsSubstitutor<'tcx> { binder_index: ty::DebruijnIndex, list: Vec, next_ty_placeholder: usize, - crate params: rustc_data_structures::fx::FxHashMap, - crate named_regions: BTreeMap, + crate params: FxIndexMap, + crate named_regions: FxIndexMap, } impl<'tcx> ParamsSubstitutor<'tcx> { @@ -996,8 +997,8 @@ impl<'tcx> ParamsSubstitutor<'tcx> { binder_index: ty::INNERMOST, list: vec![], next_ty_placeholder, - params: rustc_data_structures::fx::FxHashMap::default(), - named_regions: BTreeMap::default(), + params: rustc_data_structures::fx::FxIndexMap::default(), + named_regions: FxIndexMap::default(), } } } diff --git a/compiler/rustc_traits/src/chalk/mod.rs b/compiler/rustc_traits/src/chalk/mod.rs index 09bfdabf47373..5f892e05bdfb0 100644 --- a/compiler/rustc_traits/src/chalk/mod.rs +++ b/compiler/rustc_traits/src/chalk/mod.rs @@ -6,7 +6,7 @@ crate mod db; crate mod lowering; -use rustc_data_structures::fx::FxHashMap; +use rustc_data_structures::fx::FxIndexMap; use rustc_index::vec::IndexVec; @@ -51,7 +51,7 @@ crate fn evaluate_goal<'tcx>( ParamsSubstitutor::new(tcx, placeholders_collector.next_ty_placeholder); let obligation = obligation.fold_with(&mut params_substitutor); // FIXME(chalk): we really should be substituting these back in the solution - let _params: FxHashMap = params_substitutor.params; + let _params: FxIndexMap = params_substitutor.params; let mut regions_substitutor = RegionsSubstitutor::new(tcx, reempty_placeholder); let obligation = obligation.fold_with(&mut regions_substitutor); diff --git a/compiler/rustc_typeck/src/astconv/errors.rs b/compiler/rustc_typeck/src/astconv/errors.rs index b532c41642c6e..8e94dba57a845 100644 --- a/compiler/rustc_typeck/src/astconv/errors.rs +++ b/compiler/rustc_typeck/src/astconv/errors.rs @@ -1,5 +1,6 @@ use crate::astconv::AstConv; use rustc_data_structures::fx::FxHashMap; +use rustc_data_structures::stable_set::FxHashSet; use rustc_errors::{pluralize, struct_span_err, Applicability}; use rustc_hir as hir; use rustc_hir::def_id::DefId; @@ -9,7 +10,6 @@ use rustc_span::lev_distance::find_best_match_for_name; use rustc_span::symbol::{sym, Ident}; use rustc_span::{Span, DUMMY_SP}; -use std::collections::BTreeSet; use std::iter; impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { @@ -241,7 +241,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { /// emit a generic note suggesting using a `where` clause to constraint instead. pub(crate) fn complain_about_missing_associated_types( &self, - associated_types: FxHashMap>, + associated_types: FxHashMap>, potential_assoc_types: Vec, trait_bounds: &[hir::PolyTraitRef<'_>], ) { diff --git a/compiler/rustc_typeck/src/astconv/mod.rs b/compiler/rustc_typeck/src/astconv/mod.rs index 7c53e49e280d6..5d8a719ea854d 100644 --- a/compiler/rustc_typeck/src/astconv/mod.rs +++ b/compiler/rustc_typeck/src/astconv/mod.rs @@ -37,7 +37,6 @@ use rustc_trait_selection::traits::error_reporting::report_object_safety_error; use rustc_trait_selection::traits::wf::object_region_bounds; use smallvec::SmallVec; -use std::collections::BTreeSet; use std::slice; #[derive(Debug)] @@ -1370,7 +1369,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { } // Use a `BTreeSet` to keep output in a more consistent order. - let mut associated_types: FxHashMap> = FxHashMap::default(); + let mut associated_types: FxHashMap> = FxHashMap::default(); let regular_traits_refs_spans = bounds .trait_bounds diff --git a/compiler/rustc_typeck/src/check/method/mod.rs b/compiler/rustc_typeck/src/check/method/mod.rs index d2dc21d84f6f1..e35982d399260 100644 --- a/compiler/rustc_typeck/src/check/method/mod.rs +++ b/compiler/rustc_typeck/src/check/method/mod.rs @@ -102,7 +102,7 @@ impl<'tcx> NoMatchData<'tcx> { // A pared down enum describing just the places from which a method // candidate can arise. Used for error reporting only. -#[derive(Copy, Clone, Debug, Eq, Ord, PartialEq, PartialOrd)] +#[derive(Copy, Clone, Debug, Eq, PartialEq)] pub enum CandidateSource { ImplSource(DefId), TraitSource(DefId /* trait id */), diff --git a/compiler/rustc_typeck/src/check/method/suggest.rs b/compiler/rustc_typeck/src/check/method/suggest.rs index 56f4d5afe400d..0f1294261ade9 100644 --- a/compiler/rustc_typeck/src/check/method/suggest.rs +++ b/compiler/rustc_typeck/src/check/method/suggest.rs @@ -88,7 +88,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { err: &mut DiagnosticBuilder<'_>, mut sources: Vec, sugg_span: Span| { - sources.sort(); + // FIXME: cannot sort DefIds! + // sources.sort(); sources.dedup(); // Dynamic limit to avoid hiding just one candidate, which is silly. let limit = if sources.len() == 5 { 5 } else { 4 }; @@ -522,7 +523,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { }) .collect::>(); if !inherent_impls_candidate.is_empty() { - inherent_impls_candidate.sort(); + // inherent_impls_candidate.sort(); inherent_impls_candidate.dedup(); // number of type to shows at most. @@ -1113,14 +1114,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { }, _ => false, }); - let mut preds: Vec<_> = errors + let preds: Vec<_> = errors .iter() .filter_map(|e| match e.obligation.predicate.kind().skip_binder() { ty::PredicateKind::Trait(pred) => Some(pred), _ => None, }) .collect(); - preds.sort_by_key(|pred| (pred.def_id(), pred.self_ty())); + // preds.sort_by_key(|pred| (pred.def_id(), pred.self_ty())); let def_ids = preds .iter() .filter_map(|pred| match pred.self_ty().kind() { @@ -1401,7 +1402,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ) -> bool { if !valid_out_of_scope_traits.is_empty() { let mut candidates = valid_out_of_scope_traits; - candidates.sort(); + // candidates.sort(); candidates.dedup(); // `TryFrom` and `FromIterator` have no methods diff --git a/compiler/rustc_typeck/src/outlives/utils.rs b/compiler/rustc_typeck/src/outlives/utils.rs index 76ae2ee43566e..b3ab971cf08cc 100644 --- a/compiler/rustc_typeck/src/outlives/utils.rs +++ b/compiler/rustc_typeck/src/outlives/utils.rs @@ -1,14 +1,14 @@ +use rustc_data_structures::fx::FxHashMap; use rustc_infer::infer::outlives::components::{push_outlives_components, Component}; use rustc_middle::ty::subst::{GenericArg, GenericArgKind}; use rustc_middle::ty::{self, Region, RegionKind, Ty, TyCtxt}; use rustc_span::Span; use smallvec::smallvec; -use std::collections::BTreeMap; /// Tracks the `T: 'a` or `'a: 'a` predicates that we have inferred /// must be added to the struct header. pub type RequiredPredicates<'tcx> = - BTreeMap, ty::Region<'tcx>>, Span>; + FxHashMap, ty::Region<'tcx>>, Span>; /// Given a requirement `T: 'a` or `'b: 'a`, deduce the /// outlives_component and add it to `required_predicates` diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index e759baa045892..ea9698f5a6a21 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -31,7 +31,6 @@ use rustc_typeck::hir_ty_to_ty; use std::assert_matches::assert_matches; use std::collections::hash_map::Entry; -use std::collections::BTreeMap; use std::default::Default; use std::hash::Hash; use std::{mem, vec}; @@ -575,7 +574,7 @@ fn clean_ty_generics( ) -> Generics { // Don't populate `cx.impl_trait_bounds` before `clean`ning `where` clauses, // since `Clean for ty::Predicate` would consume them. - let mut impl_trait = BTreeMap::>::default(); + let mut impl_trait = FxHashMap::>::default(); // Bounds in the type_params and lifetimes fields are repeated in the // predicates field (see rustc_typeck::collect::ty_generics), so remove diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 3b926e444034b..f42d82fbc5cab 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -517,7 +517,7 @@ impl<'tcx> Visitor<'tcx> for EmitIgnoredResolutionErrors<'tcx> { /// `DefId` or parameter index (`ty::ParamTy.index`) of a synthetic type parameter /// for `impl Trait` in argument position. -#[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] +#[derive(Clone, Copy, PartialEq, Eq, Hash)] crate enum ImplTraitParam { DefId(DefId), ParamIndex(u32), diff --git a/src/librustdoc/html/render/search_index.rs b/src/librustdoc/html/render/search_index.rs index 87138b9571c2a..aba0928f39cc4 100644 --- a/src/librustdoc/html/render/search_index.rs +++ b/src/librustdoc/html/render/search_index.rs @@ -53,8 +53,8 @@ crate fn build_index<'tcx>(krate: &clean::Crate, cache: &mut Cache, tcx: TyCtxt< // Sort search index items. This improves the compressibility of the search index. search_index.sort_unstable_by(|k1, k2| { // `sort_unstable_by_key` produces lifetime errors - let k1 = (&k1.path, &k1.name, &k1.ty, &k1.parent); - let k2 = (&k2.path, &k2.name, &k2.ty, &k2.parent); + let k1 = (&k1.path, &k1.name, &k1.ty); + let k2 = (&k2.path, &k2.name, &k2.ty); std::cmp::Ord::cmp(&k1, &k2) });