Skip to content

Commit 6b747aa

Browse files
committed
Remove PartialOrd/Ord impl for PlaceRef
This is a new attempt at rust-lang#93315. It removes one usage of the `Ord` impl for `DefId`, which should make it easier to eventually remove that impl.
1 parent 08b4f1b commit 6b747aa

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

compiler/rustc_const_eval/src/transform/validate.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Validates the MIR to ensure that invariants are upheld.
22
3+
use rustc_data_structures::fx::FxHashSet;
34
use rustc_index::bit_set::BitSet;
45
use rustc_infer::infer::TyCtxtInferExt;
56
use rustc_middle::mir::interpret::Scalar;
@@ -701,8 +702,8 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
701702
}
702703
}
703704
let all_len = self.place_cache.len();
704-
self.place_cache.sort_unstable();
705-
self.place_cache.dedup();
705+
let mut dedup = FxHashSet::default();
706+
self.place_cache.retain(|p| dedup.insert(*p));
706707
let has_duplicates = all_len != self.place_cache.len();
707708
if has_duplicates {
708709
self.fail(

compiler/rustc_middle/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#![feature(get_mut_unchecked)]
3636
#![feature(if_let_guard)]
3737
#![feature(map_first_last)]
38+
#![feature(negative_impls)]
3839
#![feature(never_type)]
3940
#![feature(extern_types)]
4041
#![feature(new_uninit)]

compiler/rustc_middle/src/mir/mod.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -2084,12 +2084,18 @@ rustc_index::newtype_index! {
20842084
}
20852085
}
20862086

2087-
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
2087+
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
20882088
pub struct PlaceRef<'tcx> {
20892089
pub local: Local,
20902090
pub projection: &'tcx [PlaceElem<'tcx>],
20912091
}
20922092

2093+
// Once we stop implementing `Ord` for `DefId`,
2094+
// this impl will be unnecessary. Until then, we'll
2095+
// leave this impl in place to prevent re-adding a
2096+
// dependnecy on the `Ord` impl for `DefId`
2097+
impl<'tcx> !PartialOrd for PlaceRef<'tcx> {}
2098+
20932099
impl<'tcx> Place<'tcx> {
20942100
// FIXME change this to a const fn by also making List::empty a const fn.
20952101
pub fn return_place() -> Place<'tcx> {

compiler/rustc_mir_build/src/build/matches/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::build::ForGuard::{self, OutsideGuard, RefWithinGuard};
1111
use crate::build::{BlockAnd, BlockAndExtension, Builder};
1212
use crate::build::{GuardFrame, GuardFrameLocal, LocalsForNode};
1313
use rustc_data_structures::{
14-
fx::{FxIndexMap, FxIndexSet},
14+
fx::{FxHashSet, FxIndexMap, FxIndexSet},
1515
stack::ensure_sufficient_stack,
1616
};
1717
use rustc_hir::HirId;
@@ -1741,7 +1741,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
17411741
all_fake_borrows.push(place.as_ref());
17421742
}
17431743

1744-
all_fake_borrows.dedup();
1744+
// Deduplicate
1745+
let mut dedup = FxHashSet::default();
1746+
all_fake_borrows.retain(|b| dedup.insert(*b));
17451747

17461748
debug!("add_fake_borrows all_fake_borrows = {:?}", all_fake_borrows);
17471749

0 commit comments

Comments
 (0)