Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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‎

Lines changed: 2 additions & 2 deletions
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‎

Lines changed: 1 addition & 1 deletion
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‎

Lines changed: 12 additions & 31 deletions
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‎

Lines changed: 2 additions & 1 deletion
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‎

Lines changed: 1 addition & 1 deletion
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‎

Lines changed: 1 addition & 16 deletions
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‎

Lines changed: 2 additions & 2 deletions
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‎

Lines changed: 2 additions & 2 deletions
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‎

Lines changed: 2 additions & 4 deletions
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‎

Lines changed: 1 addition & 14 deletions
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> {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /