Auto merge of #96889 - Aaron1011:place-ref-remove, r=compiler-errors

Remove `PartialOrd`/`Ord` impl for `PlaceRef`

This is a new attempt at #93315. It removes one usage
of the `Ord` impl for `DefId`, which should make it easier
to eventually remove that impl.
This commit is contained in:
bors 2022-05-12 05:03:48 +00:00
commit 3a08bd7873
4 changed files with 15 additions and 5 deletions

View File

@ -1,5 +1,6 @@
//! Validates the MIR to ensure that invariants are upheld.
use rustc_data_structures::fx::FxHashSet;
use rustc_index::bit_set::BitSet;
use rustc_infer::infer::TyCtxtInferExt;
use rustc_middle::mir::interpret::Scalar;
@ -701,8 +702,8 @@ fn visit_terminator(&mut self, terminator: &Terminator<'tcx>, location: Location
}
}
let all_len = self.place_cache.len();
self.place_cache.sort_unstable();
self.place_cache.dedup();
let mut dedup = FxHashSet::default();
self.place_cache.retain(|p| dedup.insert(*p));
let has_duplicates = all_len != self.place_cache.len();
if has_duplicates {
self.fail(

View File

@ -35,6 +35,7 @@
#![feature(get_mut_unchecked)]
#![feature(if_let_guard)]
#![feature(map_first_last)]
#![feature(negative_impls)]
#![feature(never_type)]
#![feature(extern_types)]
#![feature(new_uninit)]

View File

@ -2084,12 +2084,18 @@ pub struct Field {
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct PlaceRef<'tcx> {
pub local: Local,
pub projection: &'tcx [PlaceElem<'tcx>],
}
// Once we stop implementing `Ord` for `DefId`,
// this impl will be unnecessary. Until then, we'll
// leave this impl in place to prevent re-adding a
// dependnecy on the `Ord` impl for `DefId`
impl<'tcx> !PartialOrd for PlaceRef<'tcx> {}
impl<'tcx> Place<'tcx> {
// FIXME change this to a const fn by also making List::empty a const fn.
pub fn return_place() -> Place<'tcx> {

View File

@ -11,7 +11,7 @@
use crate::build::{BlockAnd, BlockAndExtension, Builder};
use crate::build::{GuardFrame, GuardFrameLocal, LocalsForNode};
use rustc_data_structures::{
fx::{FxIndexMap, FxIndexSet},
fx::{FxHashSet, FxIndexMap, FxIndexSet},
stack::ensure_sufficient_stack,
};
use rustc_hir::HirId;
@ -1741,7 +1741,9 @@ fn calculate_fake_borrows<'b>(
all_fake_borrows.push(place.as_ref());
}
all_fake_borrows.dedup();
// Deduplicate
let mut dedup = FxHashSet::default();
all_fake_borrows.retain(|b| dedup.insert(*b));
debug!("add_fake_borrows all_fake_borrows = {:?}", all_fake_borrows);