From 459ea32a278b64c7a0dbf63ca258786d6fb89a1a Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Thu, 21 Mar 2024 14:02:13 +0000 Subject: [PATCH] Remove `Partial/Ord` from `BoundRegion` --- compiler/rustc_infer/src/infer/error_reporting/mod.rs | 3 ++- compiler/rustc_middle/src/ty/fold.rs | 6 ++---- compiler/rustc_middle/src/ty/print/pretty.rs | 10 +++++----- compiler/rustc_middle/src/ty/region.rs | 6 +++--- compiler/rustc_trait_selection/src/traits/util.rs | 11 ++++++----- tests/ui/anonymous-higher-ranked-lifetime.stderr | 4 ++-- 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index 82634f7308d..d6a3f756eeb 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -1074,7 +1074,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { let (sig, reg) = ty::print::FmtPrinter::new(self.tcx, Namespace::TypeNS) .name_all_regions(sig) .unwrap(); - let lts: Vec = reg.into_values().map(|kind| kind.to_string()).collect(); + let lts: Vec = + reg.into_items().map(|(_, kind)| kind.to_string()).into_sorted_stable_ord(); (if lts.is_empty() { String::new() } else { format!("for<{}> ", lts.join(", ")) }, sig) }; diff --git a/compiler/rustc_middle/src/ty/fold.rs b/compiler/rustc_middle/src/ty/fold.rs index b57d4f372a7..fd3bee16e26 100644 --- a/compiler/rustc_middle/src/ty/fold.rs +++ b/compiler/rustc_middle/src/ty/fold.rs @@ -2,8 +2,6 @@ use crate::ty::{self, Binder, BoundTy, Ty, TyCtxt, TypeVisitableExt}; use rustc_data_structures::fx::FxIndexMap; use rustc_hir::def_id::DefId; -use std::collections::BTreeMap; - pub use rustc_type_ir::fold::{FallibleTypeFolder, TypeFoldable, TypeFolder, TypeSuperFoldable}; /////////////////////////////////////////////////////////////////////////// @@ -254,12 +252,12 @@ impl<'tcx> TyCtxt<'tcx> { self, value: Binder<'tcx, T>, mut fld_r: F, - ) -> (T, BTreeMap>) + ) -> (T, FxIndexMap>) where F: FnMut(ty::BoundRegion) -> ty::Region<'tcx>, T: TypeFoldable>, { - let mut region_map = BTreeMap::new(); + let mut region_map = FxIndexMap::default(); let real_fld_r = |br: ty::BoundRegion| *region_map.entry(br).or_insert_with(|| fld_r(br)); let value = self.instantiate_bound_regions_uncached(value, real_fld_r); (value, region_map) diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 914b19efc7e..5ff98dc8c87 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -10,6 +10,7 @@ use crate::ty::{ use rustc_apfloat::ieee::{Double, Single}; use rustc_apfloat::Float; use rustc_data_structures::fx::{FxHashMap, FxIndexMap}; +use rustc_data_structures::unord::UnordMap; use rustc_hir as hir; use rustc_hir::def::{self, CtorKind, DefKind, Namespace}; use rustc_hir::def_id::{DefIdMap, DefIdSet, ModDefId, CRATE_DEF_ID, LOCAL_CRATE}; @@ -24,7 +25,6 @@ use rustc_target::spec::abi::Abi; use smallvec::SmallVec; use std::cell::Cell; -use std::collections::BTreeMap; use std::fmt::{self, Write as _}; use std::iter; use std::ops::{Deref, DerefMut}; @@ -2537,7 +2537,7 @@ impl<'tcx> FmtPrinter<'_, 'tcx> { struct RegionFolder<'a, 'tcx> { tcx: TyCtxt<'tcx>, current_index: ty::DebruijnIndex, - region_map: BTreeMap>, + region_map: UnordMap>, name: &'a mut ( dyn FnMut( Option, // Debruijn index of the folded late-bound region @@ -2614,7 +2614,7 @@ impl<'tcx> FmtPrinter<'_, 'tcx> { pub fn name_all_regions( &mut self, value: &ty::Binder<'tcx, T>, - ) -> Result<(T, BTreeMap>), fmt::Error> + ) -> Result<(T, UnordMap>), fmt::Error> where T: Print<'tcx, Self> + TypeFoldable>, { @@ -2691,7 +2691,7 @@ impl<'tcx> FmtPrinter<'_, 'tcx> { write!(self, "{var:?}")?; } start_or_continue(self, "", "> "); - (value.clone().skip_binder(), BTreeMap::default()) + (value.clone().skip_binder(), UnordMap::default()) } else { let tcx = self.tcx; @@ -2763,7 +2763,7 @@ impl<'tcx> FmtPrinter<'_, 'tcx> { tcx, current_index: ty::INNERMOST, name: &mut name, - region_map: BTreeMap::new(), + region_map: UnordMap::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/region.rs b/compiler/rustc_middle/src/ty/region.rs index 821642b8ab6..983340bd625 100644 --- a/compiler/rustc_middle/src/ty/region.rs +++ b/compiler/rustc_middle/src/ty/region.rs @@ -358,7 +358,7 @@ impl Atom for RegionVid { } } -#[derive(Clone, PartialEq, PartialOrd, Eq, Ord, Hash, TyEncodable, TyDecodable, Copy)] +#[derive(Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable, Copy)] #[derive(HashStable)] /// The parameter representation of late-bound function parameters, "some region /// at least as big as the scope `fr.scope`". @@ -367,7 +367,7 @@ pub struct LateParamRegion { 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) @@ -384,7 +384,7 @@ pub enum BoundRegionKind { BrEnv, } -#[derive(Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable, PartialOrd, Ord)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable)] #[derive(HashStable)] pub struct BoundRegion { pub var: BoundVar, diff --git a/compiler/rustc_trait_selection/src/traits/util.rs b/compiler/rustc_trait_selection/src/traits/util.rs index c9d76aa6ee9..29d063321a7 100644 --- a/compiler/rustc_trait_selection/src/traits/util.rs +++ b/compiler/rustc_trait_selection/src/traits/util.rs @@ -431,7 +431,7 @@ 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_regions: FxIndexMap, mapped_types: FxIndexMap, mapped_consts: BTreeMap, // The current depth relative to *this* folding, *not* the entire normalization. In other words, @@ -451,11 +451,12 @@ impl<'me, 'tcx> BoundVarReplacer<'me, 'tcx> { value: T, ) -> ( T, - BTreeMap, + FxIndexMap, FxIndexMap, BTreeMap, ) { - let mapped_regions: BTreeMap = BTreeMap::new(); + let mapped_regions: FxIndexMap = + FxIndexMap::default(); let mapped_types: FxIndexMap = FxIndexMap::default(); let mapped_consts: BTreeMap = BTreeMap::new(); @@ -574,7 +575,7 @@ impl<'tcx> TypeFolder> 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<'tcx>, - mapped_regions: BTreeMap, + mapped_regions: FxIndexMap, mapped_types: FxIndexMap, mapped_consts: BTreeMap, universe_indices: &'me [Option], @@ -584,7 +585,7 @@ pub struct PlaceholderReplacer<'me, 'tcx> { impl<'me, 'tcx> PlaceholderReplacer<'me, 'tcx> { pub fn replace_placeholders>>( infcx: &'me InferCtxt<'tcx>, - mapped_regions: BTreeMap, + mapped_regions: FxIndexMap, mapped_types: FxIndexMap, mapped_consts: BTreeMap, universe_indices: &'me [Option], diff --git a/tests/ui/anonymous-higher-ranked-lifetime.stderr b/tests/ui/anonymous-higher-ranked-lifetime.stderr index cc27a0fcf95..c28d856ad55 100644 --- a/tests/ui/anonymous-higher-ranked-lifetime.stderr +++ b/tests/ui/anonymous-higher-ranked-lifetime.stderr @@ -70,7 +70,7 @@ LL | f4(|_: (), _: ()| {}); | | found signature defined here | expected due to this | - = note: expected closure signature `for<'r, 'a> fn(&'a (), &'r ()) -> _` + = note: expected closure signature `for<'a, 'r> fn(&'a (), &'r ()) -> _` found closure signature `fn((), ()) -> _` note: required by a bound in `f4` --> $DIR/anonymous-higher-ranked-lifetime.rs:19:25 @@ -217,7 +217,7 @@ LL | h2(|_: (), _: (), _: (), _: ()| {}); | | found signature defined here | expected due to this | - = note: expected closure signature `for<'t0, 'a> fn(&'a (), Box<(dyn for<'a> Fn(&'a ()) + 'static)>, &'t0 (), for<'a, 'b> fn(&'a (), &'b ())) -> _` + = note: expected closure signature `for<'a, 't0> fn(&'a (), Box<(dyn for<'a> Fn(&'a ()) + 'static)>, &'t0 (), for<'a, 'b> fn(&'a (), &'b ())) -> _` found closure signature `fn((), (), (), ()) -> _` note: required by a bound in `h2` --> $DIR/anonymous-higher-ranked-lifetime.rs:30:25