Skip to content

Commit f3f865e

Browse files
committed
Remove ordering traits from HirId
Use indexmap where necessary to maintain ordering
1 parent e6ff0ba commit f3f865e

File tree

10 files changed

+24
-37
lines changed

10 files changed

+24
-37
lines changed

Cargo.lock

+2
Original file line numberDiff line numberDiff line change
@@ -3654,6 +3654,7 @@ name = "rustc_borrowck"
36543654
version = "0.0.0"
36553655
dependencies = [
36563656
"either",
3657+
"indexmap",
36573658
"itertools 0.9.0",
36583659
"polonius-engine",
36593660
"rustc_const_eval",
@@ -4568,6 +4569,7 @@ dependencies = [
45684569
name = "rustc_typeck"
45694570
version = "0.0.0"
45704571
dependencies = [
4572+
"indexmap",
45714573
"rustc_arena",
45724574
"rustc_ast",
45734575
"rustc_attr",

compiler/rustc_borrowck/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ rustc_target = { path = "../rustc_target" }
2828
rustc_trait_selection = { path = "../rustc_trait_selection" }
2929
rustc_traits = { path = "../rustc_traits" }
3030
rustc_span = { path = "../rustc_span" }
31+
indexmap = "1.7.0"

compiler/rustc_borrowck/src/constraints/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ crate mod graph;
1313
/// constraints of the form `R1: R2`. Each constraint is identified by
1414
/// a unique `OutlivesConstraintIndex` and you can index into the set
1515
/// (`constraint_set[i]`) to access the constraint details.
16-
#[derive(Clone, Default)]
16+
#[derive(Clone, Default, Hash)]
1717
crate struct OutlivesConstraintSet<'tcx> {
1818
outlives: IndexVec<OutlivesConstraintIndex, OutlivesConstraint<'tcx>>,
1919
}
@@ -72,7 +72,7 @@ impl<'tcx> Index<OutlivesConstraintIndex> for OutlivesConstraintSet<'tcx> {
7272
}
7373
}
7474

75-
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord)]
75+
#[derive(Clone, PartialEq, Eq, Hash)]
7676
pub struct OutlivesConstraint<'tcx> {
7777
// NB. The ordering here is not significant for correctness, but
7878
// it is for convenience. Before we dump the constraints in the

compiler/rustc_borrowck/src/region_infer/dump_mir.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
7171
}
7272
}
7373

74-
let mut constraints: Vec<_> = self.constraints.outlives().iter().collect();
75-
constraints.sort();
74+
let constraints: indexmap::IndexSet<_> = self.constraints.outlives().iter().collect();
7675
for constraint in &constraints {
7776
let OutlivesConstraint { sup, sub, locations, category, variance_info: _ } = constraint;
7877
let (name, arg) = match locations {

compiler/rustc_borrowck/src/region_infer/mod.rs

+10-14
Original file line numberDiff line numberDiff line change
@@ -611,8 +611,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
611611
#[instrument(skip(self, _body), level = "debug")]
612612
fn propagate_constraints(&mut self, _body: &Body<'tcx>) {
613613
debug!("constraints={:#?}", {
614-
let mut constraints: Vec<_> = self.constraints.outlives().iter().collect();
615-
constraints.sort();
614+
let constraints: indexmap::IndexSet<_> = self.constraints.outlives().iter().collect();
616615
constraints
617616
.into_iter()
618617
.map(|c| (c, self.constraint_sccs.scc(c.sup), self.constraint_sccs.scc(c.sub)))
@@ -2006,7 +2005,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
20062005
.unwrap_or_else(|| ObligationCauseCode::MiscObligation);
20072006

20082007
// Classify each of the constraints along the path.
2009-
let mut categorized_path: Vec<BlameConstraint<'tcx>> = path
2008+
let mut categorized_path: indexmap::IndexSet<BlameConstraint<'tcx>> = path
20102009
.iter()
20112010
.map(|constraint| {
20122011
if constraint.category == ConstraintCategory::ClosureBounds {
@@ -2130,7 +2129,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
21302129
);
21312130

21322131
if let Some(i) = best_choice {
2133-
if let Some(next) = categorized_path.get(i + 1) {
2132+
if let Some(next) = categorized_path.get_index(i + 1) {
21342133
if matches!(categorized_path[i].category, ConstraintCategory::Return(_))
21352134
&& next.category == ConstraintCategory::OpaqueType
21362135
{
@@ -2151,22 +2150,19 @@ impl<'tcx> RegionInferenceContext<'tcx> {
21512150
});
21522151

21532152
if let Some(field) = field {
2154-
categorized_path[i].category =
2153+
let mut blame_vec: Vec<_> = categorized_path.into_iter().collect();
2154+
blame_vec[i].category =
21552155
ConstraintCategory::Return(ReturnConstraint::ClosureUpvar(field));
2156+
let updated_categorized_path: indexmap::IndexSet<_> =
2157+
blame_vec.into_iter().collect();
2158+
categorized_path = updated_categorized_path
21562159
}
21572160
}
21582161

21592162
return categorized_path[i].clone();
21602163
}
21612164

2162-
// If that search fails, that is.. unusual. Maybe everything
2163-
// is in the same SCC or something. In that case, find what
2164-
// appears to be the most interesting point to report to the
2165-
// user via an even more ad-hoc guess.
2166-
categorized_path.sort_by(|p0, p1| p0.category.cmp(&p1.category));
2167-
debug!("best_blame_constraint: sorted_path={:#?}", categorized_path);
2168-
2169-
categorized_path.remove(0)
2165+
categorized_path.shift_remove_index(0).unwrap()
21702166
}
21712167

21722168
crate fn universe_info(&self, universe: ty::UniverseIndex) -> UniverseInfo<'tcx> {
@@ -2266,7 +2262,7 @@ impl<'tcx> ClosureRegionRequirementsExt<'tcx> for ClosureRegionRequirements<'tcx
22662262
}
22672263
}
22682264

2269-
#[derive(Clone, Debug)]
2265+
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
22702266
pub struct BlameConstraint<'tcx> {
22712267
pub category: ConstraintCategory,
22722268
pub from_closure: bool,

compiler/rustc_hir/src/hir_id.rs

-12
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,6 @@ impl fmt::Display for HirId {
4444
}
4545
}
4646

47-
impl Ord for HirId {
48-
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
49-
(self.index()).cmp(&(other.index()))
50-
}
51-
}
52-
53-
impl PartialOrd for HirId {
54-
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
55-
Some(self.cmp(&other))
56-
}
57-
}
58-
5947
rustc_data_structures::define_id_collections!(HirIdMap, HirIdSet, HirId);
6048
rustc_data_structures::define_id_collections!(ItemLocalMap, ItemLocalSet, ItemLocalId);
6149

compiler/rustc_middle/src/mir/query.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ rustc_data_structures::static_assert_size!(ConstraintCategory, 12);
318318
/// order of the category, thereby influencing diagnostic output.
319319
///
320320
/// See also `rustc_const_eval::borrow_check::constraints`.
321-
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)]
321+
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
322322
#[derive(TyEncodable, TyDecodable, HashStable)]
323323
pub enum ConstraintCategory {
324324
Return(ReturnConstraint),
@@ -358,7 +358,7 @@ pub enum ConstraintCategory {
358358
Internal,
359359
}
360360

361-
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)]
361+
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
362362
#[derive(TyEncodable, TyDecodable, HashStable)]
363363
pub enum ReturnConstraint {
364364
Normal,

compiler/rustc_middle/src/ty/sty.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2276,7 +2276,7 @@ impl<'tcx> TyS<'tcx> {
22762276
/// a miscompilation or unsoundness.
22772277
///
22782278
/// When in doubt, use `VarianceDiagInfo::default()`
2279-
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord)]
2279+
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
22802280
pub enum VarianceDiagInfo<'tcx> {
22812281
/// No additional information - this is the default.
22822282
/// We will not add any additional information to error messages.
@@ -2296,7 +2296,7 @@ pub enum VarianceDiagInfo<'tcx> {
22962296
},
22972297
}
22982298

2299-
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
2299+
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
23002300
pub enum VarianceDiagMutKind {
23012301
/// A mutable raw pointer (`*mut T`)
23022302
RawPtr,

compiler/rustc_typeck/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ rustc_infer = { path = "../rustc_infer" }
2727
rustc_trait_selection = { path = "../rustc_trait_selection" }
2828
rustc_ty_utils = { path = "../rustc_ty_utils" }
2929
rustc_lint = { path = "../rustc_lint" }
30+
indexmap = "1.7.0"

compiler/rustc_typeck/src/check/upvar.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
use super::FnCtxt;
3434

3535
use crate::expr_use_visitor as euv;
36+
use indexmap::IndexSet;
3637
use rustc_data_structures::fx::FxIndexMap;
3738
use rustc_errors::Applicability;
3839
use rustc_hir as hir;
@@ -86,7 +87,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
8687
/// Intermediate format to store the hir_id pointing to the use that resulted in the
8788
/// corresponding place being captured and a String which contains the captured value's
8889
/// name (i.e: a.b.c)
89-
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
90+
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
9091
enum UpvarMigrationInfo {
9192
/// We previously captured all of `x`, but now we capture some sub-path.
9293
CapturingPrecise { source_expr: Option<hir::HirId>, var_name: String },
@@ -1186,8 +1187,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11861187
capture_diagnostic.insert(key.clone());
11871188
}
11881189

1189-
let mut capture_diagnostic = capture_diagnostic.into_iter().collect::<Vec<_>>();
1190-
capture_diagnostic.sort();
1190+
let capture_diagnostic: IndexSet<_> = capture_diagnostic.into_iter().collect();
11911191
for captures_info in capture_diagnostic {
11921192
// Get the auto trait reasons of why migration is needed because of that capture, if there are any
11931193
let capture_trait_reasons =

0 commit comments

Comments
 (0)