Skip to content

Commit 459ea32

Browse files
committed
Remove Partial/Ord from BoundRegion
1 parent e87d108 commit 459ea32

File tree

6 files changed

+20
-20
lines changed

6 files changed

+20
-20
lines changed

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1074,7 +1074,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
10741074
let (sig, reg) = ty::print::FmtPrinter::new(self.tcx, Namespace::TypeNS)
10751075
.name_all_regions(sig)
10761076
.unwrap();
1077-
let lts: Vec<String> = reg.into_values().map(|kind| kind.to_string()).collect();
1077+
let lts: Vec<String> =
1078+
reg.into_items().map(|(_, kind)| kind.to_string()).into_sorted_stable_ord();
10781079
(if lts.is_empty() { String::new() } else { format!("for<{}> ", lts.join(", ")) }, sig)
10791080
};
10801081

compiler/rustc_middle/src/ty/fold.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ use crate::ty::{self, Binder, BoundTy, Ty, TyCtxt, TypeVisitableExt};
22
use rustc_data_structures::fx::FxIndexMap;
33
use rustc_hir::def_id::DefId;
44

5-
use std::collections::BTreeMap;
6-
75
pub use rustc_type_ir::fold::{FallibleTypeFolder, TypeFoldable, TypeFolder, TypeSuperFoldable};
86

97
///////////////////////////////////////////////////////////////////////////
@@ -254,12 +252,12 @@ impl<'tcx> TyCtxt<'tcx> {
254252
self,
255253
value: Binder<'tcx, T>,
256254
mut fld_r: F,
257-
) -> (T, BTreeMap<ty::BoundRegion, ty::Region<'tcx>>)
255+
) -> (T, FxIndexMap<ty::BoundRegion, ty::Region<'tcx>>)
258256
where
259257
F: FnMut(ty::BoundRegion) -> ty::Region<'tcx>,
260258
T: TypeFoldable<TyCtxt<'tcx>>,
261259
{
262-
let mut region_map = BTreeMap::new();
260+
let mut region_map = FxIndexMap::default();
263261
let real_fld_r = |br: ty::BoundRegion| *region_map.entry(br).or_insert_with(|| fld_r(br));
264262
let value = self.instantiate_bound_regions_uncached(value, real_fld_r);
265263
(value, region_map)

compiler/rustc_middle/src/ty/print/pretty.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use crate::ty::{
1010
use rustc_apfloat::ieee::{Double, Single};
1111
use rustc_apfloat::Float;
1212
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
13+
use rustc_data_structures::unord::UnordMap;
1314
use rustc_hir as hir;
1415
use rustc_hir::def::{self, CtorKind, DefKind, Namespace};
1516
use rustc_hir::def_id::{DefIdMap, DefIdSet, ModDefId, CRATE_DEF_ID, LOCAL_CRATE};
@@ -24,7 +25,6 @@ use rustc_target::spec::abi::Abi;
2425
use smallvec::SmallVec;
2526

2627
use std::cell::Cell;
27-
use std::collections::BTreeMap;
2828
use std::fmt::{self, Write as _};
2929
use std::iter;
3030
use std::ops::{Deref, DerefMut};
@@ -2537,7 +2537,7 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
25372537
struct RegionFolder<'a, 'tcx> {
25382538
tcx: TyCtxt<'tcx>,
25392539
current_index: ty::DebruijnIndex,
2540-
region_map: BTreeMap<ty::BoundRegion, ty::Region<'tcx>>,
2540+
region_map: UnordMap<ty::BoundRegion, ty::Region<'tcx>>,
25412541
name: &'a mut (
25422542
dyn FnMut(
25432543
Option<ty::DebruijnIndex>, // Debruijn index of the folded late-bound region
@@ -2614,7 +2614,7 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
26142614
pub fn name_all_regions<T>(
26152615
&mut self,
26162616
value: &ty::Binder<'tcx, T>,
2617-
) -> Result<(T, BTreeMap<ty::BoundRegion, ty::Region<'tcx>>), fmt::Error>
2617+
) -> Result<(T, UnordMap<ty::BoundRegion, ty::Region<'tcx>>), fmt::Error>
26182618
where
26192619
T: Print<'tcx, Self> + TypeFoldable<TyCtxt<'tcx>>,
26202620
{
@@ -2691,7 +2691,7 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
26912691
write!(self, "{var:?}")?;
26922692
}
26932693
start_or_continue(self, "", "> ");
2694-
(value.clone().skip_binder(), BTreeMap::default())
2694+
(value.clone().skip_binder(), UnordMap::default())
26952695
} else {
26962696
let tcx = self.tcx;
26972697

@@ -2763,7 +2763,7 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
27632763
tcx,
27642764
current_index: ty::INNERMOST,
27652765
name: &mut name,
2766-
region_map: BTreeMap::new(),
2766+
region_map: UnordMap::default(),
27672767
};
27682768
let new_value = value.clone().skip_binder().fold_with(&mut folder);
27692769
let region_map = folder.region_map;

compiler/rustc_middle/src/ty/region.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ impl Atom for RegionVid {
358358
}
359359
}
360360

361-
#[derive(Clone, PartialEq, PartialOrd, Eq, Ord, Hash, TyEncodable, TyDecodable, Copy)]
361+
#[derive(Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable, Copy)]
362362
#[derive(HashStable)]
363363
/// The parameter representation of late-bound function parameters, "some region
364364
/// at least as big as the scope `fr.scope`".
@@ -367,7 +367,7 @@ pub struct LateParamRegion {
367367
pub bound_region: BoundRegionKind,
368368
}
369369

370-
#[derive(Clone, PartialEq, PartialOrd, Eq, Ord, Hash, TyEncodable, TyDecodable, Copy)]
370+
#[derive(Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable, Copy)]
371371
#[derive(HashStable)]
372372
pub enum BoundRegionKind {
373373
/// An anonymous region parameter for a given fn (&T)
@@ -384,7 +384,7 @@ pub enum BoundRegionKind {
384384
BrEnv,
385385
}
386386

387-
#[derive(Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable, PartialOrd, Ord)]
387+
#[derive(Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable)]
388388
#[derive(HashStable)]
389389
pub struct BoundRegion {
390390
pub var: BoundVar,

compiler/rustc_trait_selection/src/traits/util.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ pub struct BoundVarReplacer<'me, 'tcx> {
431431
// These three maps track the bound variable that were replaced by placeholders. It might be
432432
// nice to remove these since we already have the `kind` in the placeholder; we really just need
433433
// the `var` (but we *could* bring that into scope if we were to track them as we pass them).
434-
mapped_regions: BTreeMap<ty::PlaceholderRegion, ty::BoundRegion>,
434+
mapped_regions: FxIndexMap<ty::PlaceholderRegion, ty::BoundRegion>,
435435
mapped_types: FxIndexMap<ty::PlaceholderType, ty::BoundTy>,
436436
mapped_consts: BTreeMap<ty::PlaceholderConst, ty::BoundVar>,
437437
// The current depth relative to *this* folding, *not* the entire normalization. In other words,
@@ -451,11 +451,12 @@ impl<'me, 'tcx> BoundVarReplacer<'me, 'tcx> {
451451
value: T,
452452
) -> (
453453
T,
454-
BTreeMap<ty::PlaceholderRegion, ty::BoundRegion>,
454+
FxIndexMap<ty::PlaceholderRegion, ty::BoundRegion>,
455455
FxIndexMap<ty::PlaceholderType, ty::BoundTy>,
456456
BTreeMap<ty::PlaceholderConst, ty::BoundVar>,
457457
) {
458-
let mapped_regions: BTreeMap<ty::PlaceholderRegion, ty::BoundRegion> = BTreeMap::new();
458+
let mapped_regions: FxIndexMap<ty::PlaceholderRegion, ty::BoundRegion> =
459+
FxIndexMap::default();
459460
let mapped_types: FxIndexMap<ty::PlaceholderType, ty::BoundTy> = FxIndexMap::default();
460461
let mapped_consts: BTreeMap<ty::PlaceholderConst, ty::BoundVar> = BTreeMap::new();
461462

@@ -574,7 +575,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for BoundVarReplacer<'_, 'tcx> {
574575
/// The inverse of [`BoundVarReplacer`]: replaces placeholders with the bound vars from which they came.
575576
pub struct PlaceholderReplacer<'me, 'tcx> {
576577
infcx: &'me InferCtxt<'tcx>,
577-
mapped_regions: BTreeMap<ty::PlaceholderRegion, ty::BoundRegion>,
578+
mapped_regions: FxIndexMap<ty::PlaceholderRegion, ty::BoundRegion>,
578579
mapped_types: FxIndexMap<ty::PlaceholderType, ty::BoundTy>,
579580
mapped_consts: BTreeMap<ty::PlaceholderConst, ty::BoundVar>,
580581
universe_indices: &'me [Option<ty::UniverseIndex>],
@@ -584,7 +585,7 @@ pub struct PlaceholderReplacer<'me, 'tcx> {
584585
impl<'me, 'tcx> PlaceholderReplacer<'me, 'tcx> {
585586
pub fn replace_placeholders<T: TypeFoldable<TyCtxt<'tcx>>>(
586587
infcx: &'me InferCtxt<'tcx>,
587-
mapped_regions: BTreeMap<ty::PlaceholderRegion, ty::BoundRegion>,
588+
mapped_regions: FxIndexMap<ty::PlaceholderRegion, ty::BoundRegion>,
588589
mapped_types: FxIndexMap<ty::PlaceholderType, ty::BoundTy>,
589590
mapped_consts: BTreeMap<ty::PlaceholderConst, ty::BoundVar>,
590591
universe_indices: &'me [Option<ty::UniverseIndex>],

tests/ui/anonymous-higher-ranked-lifetime.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ LL | f4(|_: (), _: ()| {});
7070
| | found signature defined here
7171
| expected due to this
7272
|
73-
= note: expected closure signature `for<'r, 'a> fn(&'a (), &'r ()) -> _`
73+
= note: expected closure signature `for<'a, 'r> fn(&'a (), &'r ()) -> _`
7474
found closure signature `fn((), ()) -> _`
7575
note: required by a bound in `f4`
7676
--> $DIR/anonymous-higher-ranked-lifetime.rs:19:25
@@ -217,7 +217,7 @@ LL | h2(|_: (), _: (), _: (), _: ()| {});
217217
| | found signature defined here
218218
| expected due to this
219219
|
220-
= note: expected closure signature `for<'t0, 'a> fn(&'a (), Box<(dyn for<'a> Fn(&'a ()) + 'static)>, &'t0 (), for<'a, 'b> fn(&'a (), &'b ())) -> _`
220+
= note: expected closure signature `for<'a, 't0> fn(&'a (), Box<(dyn for<'a> Fn(&'a ()) + 'static)>, &'t0 (), for<'a, 'b> fn(&'a (), &'b ())) -> _`
221221
found closure signature `fn((), (), (), ()) -> _`
222222
note: required by a bound in `h2`
223223
--> $DIR/anonymous-higher-ranked-lifetime.rs:30:25

0 commit comments

Comments
 (0)