Skip to content

Commit 5f4ac61

Browse files
committed
Remove DefId's Partial/Ord impls
1 parent e522d29 commit 5f4ac61

File tree

5 files changed

+10
-29
lines changed

5 files changed

+10
-29
lines changed

compiler/rustc_span/src/def_id.rs

-18
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,6 @@ rustc_index::newtype_index! {
218218
///
219219
/// You can create a `DefId` from a `LocalDefId` using `local_def_id.to_def_id()`.
220220
#[derive(Clone, PartialEq, Eq, Copy)]
221-
// Don't derive order on 64-bit big-endian, so we can be consistent regardless of field order.
222-
#[cfg_attr(not(all(target_pointer_width = "64", target_endian = "big")), derive(PartialOrd, Ord))]
223221
// On below-64 bit systems we can simply use the derived `Hash` impl
224222
#[cfg_attr(not(target_pointer_width = "64"), derive(Hash))]
225223
#[repr(C)]
@@ -261,22 +259,6 @@ impl Hash for DefId {
261259
}
262260
}
263261

264-
// Implement the same comparison as derived with the other field order.
265-
#[cfg(all(target_pointer_width = "64", target_endian = "big"))]
266-
impl Ord for DefId {
267-
#[inline]
268-
fn cmp(&self, other: &DefId) -> std::cmp::Ordering {
269-
Ord::cmp(&(self.index, self.krate), &(other.index, other.krate))
270-
}
271-
}
272-
#[cfg(all(target_pointer_width = "64", target_endian = "big"))]
273-
impl PartialOrd for DefId {
274-
#[inline]
275-
fn partial_cmp(&self, other: &DefId) -> Option<std::cmp::Ordering> {
276-
Some(self.cmp(other))
277-
}
278-
}
279-
280262
impl DefId {
281263
/// Makes a local `DefId` from the given `DefIndex`.
282264
#[inline]

compiler/rustc_type_ir/src/interner.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::{
99
};
1010

1111
pub trait Interner: Sized {
12-
type DefId: Copy + Debug + Hash + Ord;
12+
type DefId: Copy + Debug + Hash + Eq;
1313
type AdtDef: Copy + Debug + Hash + Eq;
1414

1515
type GenericArgs: Copy

src/librustdoc/clean/mod.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use std::hash::Hash;
4141
use std::mem;
4242
use thin_vec::ThinVec;
4343

44-
use crate::core::{self, DocContext, ImplTraitParam};
44+
use crate::core::{self, DocContext};
4545
use crate::formats::item_type::ItemType;
4646
use crate::visit_ast::Module as DocModule;
4747

@@ -761,7 +761,7 @@ fn clean_ty_generics<'tcx>(
761761
) -> Generics {
762762
// Don't populate `cx.impl_trait_bounds` before `clean`ning `where` clauses,
763763
// since `Clean for ty::Predicate` would consume them.
764-
let mut impl_trait = BTreeMap::<ImplTraitParam, Vec<GenericBound>>::default();
764+
let mut impl_trait = BTreeMap::<u32, Vec<GenericBound>>::default();
765765

766766
// Bounds in the type_params and lifetimes fields are repeated in the
767767
// predicates field (see rustc_hir_analysis::collect::ty_generics), so remove
@@ -778,7 +778,7 @@ fn clean_ty_generics<'tcx>(
778778
return None;
779779
}
780780
if synthetic {
781-
impl_trait.insert(param.index.into(), vec![]);
781+
impl_trait.insert(param.index, vec![]);
782782
return None;
783783
}
784784
Some(clean_generic_param_def(param, cx))
@@ -823,7 +823,7 @@ fn clean_ty_generics<'tcx>(
823823
})();
824824

825825
if let Some(param_idx) = param_idx
826-
&& let Some(bounds) = impl_trait.get_mut(&param_idx.into())
826+
&& let Some(bounds) = impl_trait.get_mut(&param_idx)
827827
{
828828
let pred = clean_predicate(*pred, cx)?;
829829

@@ -847,7 +847,7 @@ fn clean_ty_generics<'tcx>(
847847
})
848848
.collect::<Vec<_>>();
849849

850-
for (param, mut bounds) in impl_trait {
850+
for (idx, mut bounds) in impl_trait {
851851
let mut has_sized = false;
852852
bounds.retain(|b| {
853853
if b.is_sized_bound(cx) {
@@ -870,15 +870,14 @@ fn clean_ty_generics<'tcx>(
870870
bounds.insert(0, GenericBound::sized(cx));
871871
}
872872

873-
let crate::core::ImplTraitParam::ParamIndex(idx) = param else { unreachable!() };
874873
if let Some(proj) = impl_trait_proj.remove(&idx) {
875874
for (trait_did, name, rhs) in proj {
876875
let rhs = clean_middle_term(rhs, cx);
877876
simplify::merge_bounds(cx, &mut bounds, trait_did, name, &rhs);
878877
}
879878
}
880879

881-
cx.impl_trait_bounds.insert(param, bounds);
880+
cx.impl_trait_bounds.insert(idx.into(), bounds);
882881
}
883882

884883
// Now that `cx.impl_trait_bounds` is populated, we can process

src/librustdoc/core.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ impl<'tcx> Visitor<'tcx> for EmitIgnoredResolutionErrors<'tcx> {
509509

510510
/// `DefId` or parameter index (`ty::ParamTy.index`) of a synthetic type parameter
511511
/// for `impl Trait` in argument position.
512-
#[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
512+
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
513513
pub(crate) enum ImplTraitParam {
514514
DefId(DefId),
515515
ParamIndex(u32),

src/librustdoc/html/render/search_index.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ pub(crate) fn build_index<'tcx>(
6565
// Sort search index items. This improves the compressibility of the search index.
6666
cache.search_index.sort_unstable_by(|k1, k2| {
6767
// `sort_unstable_by_key` produces lifetime errors
68-
let k1 = (&k1.path, k1.name.as_str(), &k1.ty, &k1.parent);
69-
let k2 = (&k2.path, k2.name.as_str(), &k2.ty, &k2.parent);
68+
let k1 = (&k1.path, k1.name.as_str(), &k1.ty, &k1.parent.map(|id| tcx.def_path_str(id)));
69+
let k2 = (&k2.path, k2.name.as_str(), &k2.ty, &k2.parent.map(|id| tcx.def_path_str(id)));
7070
Ord::cmp(&k1, &k2)
7171
});
7272

0 commit comments

Comments
 (0)