Skip to content

Commit 2781687

Browse files
committed
Auto merge of rust-lang#122832 - oli-obk:no_ord_def_id3, r=michaelwoerister
Remove `DefId`'s `Partial/Ord` impls work towards rust-lang#90317 based on rust-lang#122824 and rust-lang#122820 r? `@michaelwoerister`
2 parents 463a11b + bd6a96f commit 2781687

File tree

85 files changed

+451
-533
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+451
-533
lines changed

compiler/rustc_hir_analysis/src/outlives/utils.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1+
use rustc_data_structures::fx::FxIndexMap;
12
use rustc_infer::infer::outlives::components::{push_outlives_components, Component};
23
use rustc_middle::ty::{self, Region, Ty, TyCtxt};
34
use rustc_middle::ty::{GenericArg, GenericArgKind};
45
use rustc_span::Span;
56
use smallvec::smallvec;
6-
use std::collections::BTreeMap;
77

88
/// Tracks the `T: 'a` or `'a: 'a` predicates that we have inferred
99
/// must be added to the struct header.
1010
pub(crate) type RequiredPredicates<'tcx> =
11-
BTreeMap<ty::OutlivesPredicate<GenericArg<'tcx>, ty::Region<'tcx>>, Span>;
11+
FxIndexMap<ty::OutlivesPredicate<GenericArg<'tcx>, ty::Region<'tcx>>, Span>;
1212

1313
/// Given a requirement `T: 'a` or `'b: 'a`, deduce the
1414
/// outlives_component and add it to `required_predicates`

compiler/rustc_hir_typeck/src/method/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ pub struct NoMatchData<'tcx> {
8181

8282
// A pared down enum describing just the places from which a method
8383
// candidate can arise. Used for error reporting only.
84-
#[derive(Copy, Clone, Debug, Eq, Ord, PartialEq, PartialOrd)]
84+
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
8585
pub enum CandidateSource {
8686
Impl(DefId),
8787
Trait(DefId /* trait id */),

compiler/rustc_hir_typeck/src/method/suggest.rs

+12-31
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ use std::borrow::Cow;
4949
use super::probe::{AutorefOrPtrAdjustment, IsSuggestion, Mode, ProbeScope};
5050
use super::{CandidateSource, MethodError, NoMatchData};
5151
use rustc_hir::intravisit::Visitor;
52-
use std::cmp::{self, Ordering};
5352
use std::iter;
5453

5554
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
@@ -1186,7 +1185,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11861185
})
11871186
.collect::<Vec<_>>();
11881187
if !inherent_impls_candidate.is_empty() {
1189-
inherent_impls_candidate.sort();
1188+
inherent_impls_candidate.sort_by_key(|id| self.tcx.def_path_str(id));
11901189
inherent_impls_candidate.dedup();
11911190

11921191
// number of types to show at most
@@ -1567,7 +1566,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15671566
sources: &mut Vec<CandidateSource>,
15681567
sugg_span: Option<Span>,
15691568
) {
1570-
sources.sort();
1569+
sources.sort_by_key(|source| match source {
1570+
CandidateSource::Trait(id) => (0, self.tcx.def_path_str(id)),
1571+
CandidateSource::Impl(id) => (1, self.tcx.def_path_str(id)),
1572+
});
15711573
sources.dedup();
15721574
// Dynamic limit to avoid hiding just one candidate, which is silly.
15731575
let limit = if sources.len() == 5 { 5 } else { 4 };
@@ -2549,7 +2551,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
25492551
_ => None,
25502552
})
25512553
.collect();
2552-
preds.sort_by_key(|pred| (pred.def_id(), pred.self_ty()));
2554+
preds.sort_by_key(|pred| pred.trait_ref.to_string());
25532555
let def_ids = preds
25542556
.iter()
25552557
.filter_map(|pred| match pred.self_ty().kind() {
@@ -2663,7 +2665,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
26632665
traits.push(trait_pred.def_id());
26642666
}
26652667
}
2666-
traits.sort();
2668+
traits.sort_by_key(|id| self.tcx.def_path_str(id));
26672669
traits.dedup();
26682670

26692671
let len = traits.len();
@@ -2886,7 +2888,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
28862888
) -> bool {
28872889
if !valid_out_of_scope_traits.is_empty() {
28882890
let mut candidates = valid_out_of_scope_traits;
2889-
candidates.sort();
2891+
candidates.sort_by_key(|id| self.tcx.def_path_str(id));
28902892
candidates.dedup();
28912893

28922894
// `TryFrom` and `FromIterator` have no methods
@@ -3212,8 +3214,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
32123214
}
32133215

32143216
if !candidates.is_empty() {
3215-
// Sort from most relevant to least relevant.
3216-
candidates.sort_by_key(|&info| cmp::Reverse(info));
3217+
// Sort local crate results before others
3218+
candidates
3219+
.sort_by_key(|&info| (!info.def_id.is_local(), self.tcx.def_path_str(info.def_id)));
32173220
candidates.dedup();
32183221

32193222
let param_type = match rcvr_ty.kind() {
@@ -3561,33 +3564,11 @@ pub enum SelfSource<'a> {
35613564
MethodCall(&'a hir::Expr<'a> /* rcvr */),
35623565
}
35633566

3564-
#[derive(Copy, Clone)]
3567+
#[derive(Copy, Clone, PartialEq, Eq)]
35653568
pub struct TraitInfo {
35663569
pub def_id: DefId,
35673570
}
35683571

3569-
impl PartialEq for TraitInfo {
3570-
fn eq(&self, other: &TraitInfo) -> bool {
3571-
self.cmp(other) == Ordering::Equal
3572-
}
3573-
}
3574-
impl Eq for TraitInfo {}
3575-
impl PartialOrd for TraitInfo {
3576-
fn partial_cmp(&self, other: &TraitInfo) -> Option<Ordering> {
3577-
Some(self.cmp(other))
3578-
}
3579-
}
3580-
impl Ord for TraitInfo {
3581-
fn cmp(&self, other: &TraitInfo) -> Ordering {
3582-
// Local crates are more important than remote ones (local:
3583-
// `cnum == 0`), and otherwise we throw in the defid for totality.
3584-
3585-
let lhs = (other.def_id.krate, other.def_id);
3586-
let rhs = (self.def_id.krate, self.def_id);
3587-
lhs.cmp(&rhs)
3588-
}
3589-
}
3590-
35913572
/// Retrieves all traits in this crate and any dependent crates,
35923573
/// and wraps them into `TraitInfo` for custom sorting.
35933574
pub fn all_traits(tcx: TyCtxt<'_>) -> Vec<TraitInfo> {

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
10381038
let (sig, reg) = ty::print::FmtPrinter::new(self.tcx, Namespace::TypeNS)
10391039
.name_all_regions(sig)
10401040
.unwrap();
1041-
let lts: Vec<String> = reg.into_values().map(|kind| kind.to_string()).collect();
1041+
let lts: Vec<String> =
1042+
reg.into_items().map(|(_, kind)| kind.to_string()).into_sorted_stable_ord();
10421043
(if lts.is_empty() { String::new() } else { format!("for<{}> ", lts.join(", ")) }, sig)
10431044
};
10441045

compiler/rustc_middle/src/thir.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1018,7 +1018,7 @@ impl<'tcx> PatRangeBoundary<'tcx> {
10181018
(Finite(mir::Const::Ty(a)), Finite(mir::Const::Ty(b)))
10191019
if matches!(ty.kind(), ty::Uint(_) | ty::Char) =>
10201020
{
1021-
return Some(a.kind().cmp(&b.kind()));
1021+
return Some(a.to_valtree().cmp(&b.to_valtree()));
10221022
}
10231023
(
10241024
Finite(mir::Const::Val(mir::ConstValue::Scalar(Scalar::Int(a)), _)),

compiler/rustc_middle/src/ty/adt.rs

+1-16
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use rustc_span::symbol::sym;
1818
use rustc_target::abi::{ReprOptions, VariantIdx, FIRST_VARIANT};
1919

2020
use std::cell::RefCell;
21-
use std::cmp::Ordering;
2221
use std::hash::{Hash, Hasher};
2322
use std::ops::Range;
2423
use std::str;
@@ -102,20 +101,6 @@ pub struct AdtDefData {
102101
repr: ReprOptions,
103102
}
104103

105-
impl PartialOrd for AdtDefData {
106-
fn partial_cmp(&self, other: &AdtDefData) -> Option<Ordering> {
107-
Some(self.cmp(other))
108-
}
109-
}
110-
111-
/// There should be only one AdtDef for each `did`, therefore
112-
/// it is fine to implement `Ord` only based on `did`.
113-
impl Ord for AdtDefData {
114-
fn cmp(&self, other: &AdtDefData) -> Ordering {
115-
self.did.cmp(&other.did)
116-
}
117-
}
118-
119104
impl PartialEq for AdtDefData {
120105
#[inline]
121106
fn eq(&self, other: &Self) -> bool {
@@ -180,7 +165,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for AdtDefData {
180165
}
181166
}
182167

183-
#[derive(Copy, Clone, PartialEq, Eq, Hash, Ord, PartialOrd, HashStable)]
168+
#[derive(Copy, Clone, PartialEq, Eq, Hash, HashStable)]
184169
#[rustc_pass_by_value]
185170
pub struct AdtDef<'tcx>(pub Interned<'tcx, AdtDefData>);
186171

compiler/rustc_middle/src/ty/consts.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub use valtree::*;
2323
pub type ConstKind<'tcx> = IrConstKind<TyCtxt<'tcx>>;
2424

2525
/// Use this rather than `ConstData`, whenever possible.
26-
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, HashStable)]
26+
#[derive(Copy, Clone, PartialEq, Eq, Hash, HashStable)]
2727
#[rustc_pass_by_value]
2828
pub struct Const<'tcx>(pub(super) Interned<'tcx, WithCachedTypeInfo<ConstData<'tcx>>>);
2929

@@ -52,7 +52,7 @@ impl<'tcx> ConstTy<TyCtxt<'tcx>> for Const<'tcx> {
5252
}
5353

5454
/// Typed constant value.
55-
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
55+
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
5656
#[derive(HashStable, TyEncodable, TyDecodable)]
5757
pub struct ConstData<'tcx> {
5858
pub ty: Ty<'tcx>,

compiler/rustc_middle/src/ty/consts/kind.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_hir::def_id::DefId;
77
use rustc_macros::HashStable;
88

99
/// An unevaluated (potentially generic) constant used in the type-system.
10-
#[derive(Copy, Clone, Eq, PartialEq, PartialOrd, Ord, TyEncodable, TyDecodable)]
10+
#[derive(Copy, Clone, Eq, PartialEq, TyEncodable, TyDecodable)]
1111
#[derive(Hash, HashStable, TypeFoldable, TypeVisitable)]
1212
pub struct UnevaluatedConst<'tcx> {
1313
pub def: DefId,
@@ -62,7 +62,7 @@ impl<'tcx> UnevaluatedConst<'tcx> {
6262
}
6363
}
6464

65-
#[derive(Copy, Clone, Eq, PartialEq, PartialOrd, Ord, Hash)]
65+
#[derive(Copy, Clone, Eq, PartialEq, Hash)]
6666
#[derive(HashStable, TyEncodable, TyDecodable, TypeVisitable, TypeFoldable)]
6767
pub enum Expr<'tcx> {
6868
Binop(mir::BinOp, Const<'tcx>, Const<'tcx>),

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/generic_args.rs

+1-14
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use rustc_type_ir::WithCachedTypeInfo;
1717
use smallvec::SmallVec;
1818

1919
use core::intrinsics;
20-
use std::cmp::Ordering;
2120
use std::marker::PhantomData;
2221
use std::mem;
2322
use std::num::NonZero;
@@ -68,7 +67,7 @@ const TYPE_TAG: usize = 0b00;
6867
const REGION_TAG: usize = 0b01;
6968
const CONST_TAG: usize = 0b10;
7069

71-
#[derive(Debug, TyEncodable, TyDecodable, PartialEq, Eq, PartialOrd, Ord, HashStable)]
70+
#[derive(Debug, TyEncodable, TyDecodable, PartialEq, Eq, HashStable)]
7271
pub enum GenericArgKind<'tcx> {
7372
Lifetime(ty::Region<'tcx>),
7473
Type(Ty<'tcx>),
@@ -100,18 +99,6 @@ impl<'tcx> GenericArgKind<'tcx> {
10099
}
101100
}
102101

103-
impl<'tcx> Ord for GenericArg<'tcx> {
104-
fn cmp(&self, other: &GenericArg<'tcx>) -> Ordering {
105-
self.unpack().cmp(&other.unpack())
106-
}
107-
}
108-
109-
impl<'tcx> PartialOrd for GenericArg<'tcx> {
110-
fn partial_cmp(&self, other: &GenericArg<'tcx>) -> Option<Ordering> {
111-
Some(self.cmp(other))
112-
}
113-
}
114-
115102
impl<'tcx> From<ty::Region<'tcx>> for GenericArg<'tcx> {
116103
#[inline]
117104
fn from(r: ty::Region<'tcx>) -> GenericArg<'tcx> {

compiler/rustc_middle/src/ty/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ pub struct CReaderCacheKey {
517517
}
518518

519519
/// Use this rather than `TyKind`, whenever possible.
520-
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, HashStable)]
520+
#[derive(Copy, Clone, PartialEq, Eq, Hash, HashStable)]
521521
#[rustc_diagnostic_item = "Ty"]
522522
#[rustc_pass_by_value]
523523
pub struct Ty<'tcx>(Interned<'tcx, WithCachedTypeInfo<TyKind<'tcx>>>);
@@ -702,7 +702,7 @@ const TAG_MASK: usize = 0b11;
702702
const TYPE_TAG: usize = 0b00;
703703
const CONST_TAG: usize = 0b01;
704704

705-
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, TyEncodable, TyDecodable)]
705+
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable)]
706706
#[derive(HashStable, TypeFoldable, TypeVisitable)]
707707
pub enum TermKind<'tcx> {
708708
Ty(Ty<'tcx>),
@@ -980,7 +980,7 @@ impl PlaceholderLike for PlaceholderType {
980980
}
981981

982982
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, HashStable)]
983-
#[derive(TyEncodable, TyDecodable, PartialOrd, Ord)]
983+
#[derive(TyEncodable, TyDecodable)]
984984
pub struct BoundConst<'tcx> {
985985
pub var: BoundVar,
986986
pub ty: Ty<'tcx>,

compiler/rustc_middle/src/ty/predicate.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ impl<'tcx> Clause<'tcx> {
192192
}
193193
}
194194

195-
#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Ord, Eq, Hash, TyEncodable, TyDecodable)]
195+
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable)]
196196
#[derive(HashStable, TypeFoldable, TypeVisitable, Lift)]
197197
pub enum ExistentialPredicate<'tcx> {
198198
/// E.g., `Iterator`.
@@ -336,7 +336,7 @@ impl<'tcx> ty::List<ty::PolyExistentialPredicate<'tcx>> {
336336
///
337337
/// Trait references also appear in object types like `Foo<U>`, but in
338338
/// that case the `Self` parameter is absent from the generic parameters.
339-
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, TyDecodable)]
339+
#[derive(Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable)]
340340
#[derive(HashStable, TypeFoldable, TypeVisitable, Lift)]
341341
pub struct TraitRef<'tcx> {
342342
pub def_id: DefId,
@@ -420,7 +420,7 @@ impl<'tcx> IntoDiagArg for TraitRef<'tcx> {
420420
/// ```
421421
/// The generic parameters don't include the erased `Self`, only trait
422422
/// type and lifetime parameters (`[X, Y]` and `['a, 'b]` above).
423-
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, TyDecodable)]
423+
#[derive(Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable)]
424424
#[derive(HashStable, TypeFoldable, TypeVisitable, Lift)]
425425
pub struct ExistentialTraitRef<'tcx> {
426426
pub def_id: DefId,
@@ -476,7 +476,7 @@ impl<'tcx> PolyExistentialTraitRef<'tcx> {
476476
}
477477

478478
/// A `ProjectionPredicate` for an `ExistentialTraitRef`.
479-
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, TyEncodable, TyDecodable)]
479+
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, TyEncodable, TyDecodable)]
480480
#[derive(HashStable, TypeFoldable, TypeVisitable, Lift)]
481481
pub struct ExistentialProjection<'tcx> {
482482
pub def_id: DefId,

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;

0 commit comments

Comments
 (0)