Skip to content

Commit f5e1f88

Browse files
WaffleLapkindingxiangfei2009
authored andcommitted
remove implicit total orderings
1 parent 999ac5f commit f5e1f88

File tree

35 files changed

+194
-285
lines changed

35 files changed

+194
-285
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -776,10 +776,9 @@ pub enum PatKind {
776776
MacCall(P<MacCall>),
777777
}
778778

779-
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Copy)]
779+
#[derive(Clone, PartialEq, Eq, Hash, Debug, Copy)]
780780
#[derive(HashStable_Generic, Encodable, Decodable)]
781781
pub enum Mutability {
782-
// N.B. Order is deliberate, so that Not < Mut
783782
Not,
784783
Mut,
785784
}

compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -403,19 +403,22 @@ fn try_extract_error_from_region_constraints<'tcx>(
403403
mut region_var_origin: impl FnMut(RegionVid) -> RegionVariableOrigin,
404404
mut universe_of_region: impl FnMut(RegionVid) -> UniverseIndex,
405405
) -> Option<DiagnosticBuilder<'tcx, ErrorGuaranteed>> {
406-
let (sub_region, cause) =
407-
region_constraints.constraints.iter().find_map(|(constraint, cause)| {
406+
let (_, _, sub_region, cause) = region_constraints
407+
.constraints
408+
.iter()
409+
.filter_map(|(constraint, cause)| {
408410
match *constraint {
409411
Constraint::RegSubReg(sub, sup) if sup == placeholder_region && sup != sub => {
410-
Some((sub, cause.clone()))
412+
Some((1u8, None, sub, cause.clone()))
411413
}
412414
// FIXME: Should this check the universe of the var?
413415
Constraint::VarSubReg(vid, sup) if sup == placeholder_region => {
414-
Some((infcx.tcx.mk_region(ty::ReVar(vid)), cause.clone()))
416+
Some((0u8, Some(vid), infcx.tcx.mk_region(ty::ReVar(vid)), cause.clone()))
415417
}
416418
_ => None,
417419
}
418-
})?;
420+
})
421+
.min_by_key(|(discr, vid, ..)| (*discr, *vid))?;
419422

420423
debug!(?sub_region, "cause = {:#?}", cause);
421424
let error = match (error_region, *sub_region) {

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
435435

436436
// Check if we can use one of the "nice region errors".
437437
if let (Some(f), Some(o)) = (self.to_error_region(fr), self.to_error_region(outlived_fr)) {
438+
debug!("report_region_error: nice report");
438439
let infer_err = self.infcx.err_ctxt();
439440
let nice = NiceRegionError::new_from_span(&infer_err, cause.span, o, f);
440441
if let Some(diag) = nice.try_report_from_nll() {

compiler/rustc_borrowck/src/region_infer/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2173,7 +2173,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
21732173
// is in the same SCC or something. In that case, find what
21742174
// appears to be the most interesting point to report to the
21752175
// user via an even more ad-hoc guess.
2176-
categorized_path.sort_by(|p0, p1| p0.category.cmp(&p1.category));
2176+
categorized_path.sort_by_key(|p| p.category.cmp_discr());
21772177
debug!("sorted_path={:#?}", categorized_path);
21782178

21792179
(categorized_path.remove(0), extra_info)

compiler/rustc_hir_analysis/src/coherence/builtin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ pub fn coerce_unsized_info<'tcx>(tcx: TyCtxt<'tcx>, impl_did: DefId) -> CoerceUn
389389
let check_mutbl = |mt_a: ty::TypeAndMut<'tcx>,
390390
mt_b: ty::TypeAndMut<'tcx>,
391391
mk_ptr: &dyn Fn(Ty<'tcx>) -> Ty<'tcx>| {
392-
if mt_a.mutbl < mt_b.mutbl {
392+
if let (hir::Mutability::Not, hir::Mutability::Mut) = (mt_a.mutbl, mt_b.mutbl) {
393393
infcx
394394
.err_ctxt()
395395
.report_mismatched_types(

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::FxHashMap;
12
use rustc_infer::infer::outlives::components::{push_outlives_components, Component};
23
use rustc_middle::ty::subst::{GenericArg, GenericArgKind};
34
use rustc_middle::ty::{self, Region, Ty, TyCtxt};
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+
FxHashMap<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/_match.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,5 +575,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
575575
}
576576

577577
fn arms_contain_ref_bindings<'tcx>(arms: &'tcx [hir::Arm<'tcx>]) -> Option<hir::Mutability> {
578-
arms.iter().filter_map(|a| a.pat.contains_explicit_ref_binding()).max()
578+
arms.iter().filter_map(|a| a.pat.contains_explicit_ref_binding()).max_by_key(|m| match m {
579+
hir::Mutability::Not => 0u8,
580+
hir::Mutability::Mut => 1,
581+
})
579582
}

compiler/rustc_hir_typeck/src/cast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
947947
m_cast: ty::TypeAndMut<'tcx>,
948948
) -> Result<CastKind, CastError> {
949949
// array-ptr-cast: allow mut-to-mut, mut-to-const, const-to-const
950-
if m_expr.mutbl >= m_cast.mutbl {
950+
if m_expr.mutbl == m_cast.mutbl || m_expr.mutbl == hir::Mutability::Mut {
951951
if let ty::Array(ety, _) = m_expr.ty.kind() {
952952
// Due to the limitations of LLVM global constants,
953953
// region pointers end up pointing at copies of

compiler/rustc_hir_typeck/src/coercion.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,11 @@ fn coerce_mutbls<'tcx>(
110110
from_mutbl: hir::Mutability,
111111
to_mutbl: hir::Mutability,
112112
) -> RelateResult<'tcx, ()> {
113-
if from_mutbl >= to_mutbl { Ok(()) } else { Err(TypeError::Mutability) }
113+
if from_mutbl == to_mutbl || from_mutbl == hir::Mutability::Mut {
114+
Ok(())
115+
} else {
116+
Err(TypeError::Mutability)
117+
}
114118
}
115119

116120
/// Do not require any adjustments, i.e. coerce `x -> x`.

compiler/rustc_hir_typeck/src/demand.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1420,7 +1420,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14201420
(
14211421
sp,
14221422
format!("{}{derefs}", if mutbl_a != mutbl_b { mutbl_b.prefix_str() } else { "" }),
1423-
if mutbl_b <= mutbl_a { Applicability::MachineApplicable } else { Applicability::MaybeIncorrect }
1423+
if mutbl_b == mutbl_a || mutbl_b == hir::Mutability::Not { Applicability::MachineApplicable } else { Applicability::MaybeIncorrect }
14241424
)
14251425
});
14261426

0 commit comments

Comments
 (0)