diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index f2258fecfeafc..ceb49905f9c8b 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -776,10 +776,9 @@ pub enum PatKind { MacCall(P), } -#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Copy)] +#[derive(Clone, PartialEq, Eq, Hash, Debug, Copy)] #[derive(HashStable_Generic, Encodable, Decodable)] pub enum Mutability { - // N.B. Order is deliberate, so that Not < Mut Not, Mut, } diff --git a/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs b/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs index 1550958ab8eee..ddcba3c5ae71c 100644 --- a/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs @@ -403,19 +403,22 @@ fn try_extract_error_from_region_constraints<'tcx>( mut region_var_origin: impl FnMut(RegionVid) -> RegionVariableOrigin, mut universe_of_region: impl FnMut(RegionVid) -> UniverseIndex, ) -> Option> { - let (sub_region, cause) = - region_constraints.constraints.iter().find_map(|(constraint, cause)| { + let (_, _, sub_region, cause) = region_constraints + .constraints + .iter() + .filter_map(|(constraint, cause)| { match *constraint { Constraint::RegSubReg(sub, sup) if sup == placeholder_region && sup != sub => { - Some((sub, cause.clone())) + Some((1u8, None, sub, cause.clone())) } // FIXME: Should this check the universe of the var? Constraint::VarSubReg(vid, sup) if sup == placeholder_region => { - Some((infcx.tcx.mk_region(ty::ReVar(vid)), cause.clone())) + Some((0u8, Some(vid), infcx.tcx.mk_region(ty::ReVar(vid)), cause.clone())) } _ => None, } - })?; + }) + .min_by_key(|(discr, vid, ..)| (*discr, *vid))?; debug!(?sub_region, "cause = {:#?}", cause); let error = match (error_region, *sub_region) { diff --git a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs index 7901a5046abad..c961300e84b3f 100644 --- a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs @@ -435,6 +435,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { // Check if we can use one of the "nice region errors". if let (Some(f), Some(o)) = (self.to_error_region(fr), self.to_error_region(outlived_fr)) { + debug!("report_region_error: nice report"); let infer_err = self.infcx.err_ctxt(); let nice = NiceRegionError::new_from_span(&infer_err, cause.span, o, f); if let Some(diag) = nice.try_report_from_nll() { diff --git a/compiler/rustc_borrowck/src/region_infer/mod.rs b/compiler/rustc_borrowck/src/region_infer/mod.rs index f2693bded590b..140bf331d40bf 100644 --- a/compiler/rustc_borrowck/src/region_infer/mod.rs +++ b/compiler/rustc_borrowck/src/region_infer/mod.rs @@ -2173,7 +2173,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { // is in the same SCC or something. In that case, find what // appears to be the most interesting point to report to the // user via an even more ad-hoc guess. - categorized_path.sort_by(|p0, p1| p0.category.cmp(&p1.category)); + categorized_path.sort_by_key(|p| p.category.cmp_discr()); debug!("sorted_path={:#?}", categorized_path); (categorized_path.remove(0), extra_info) diff --git a/compiler/rustc_hir_analysis/src/coherence/builtin.rs b/compiler/rustc_hir_analysis/src/coherence/builtin.rs index 8c2423e3ca0d1..ffd923a367490 100644 --- a/compiler/rustc_hir_analysis/src/coherence/builtin.rs +++ b/compiler/rustc_hir_analysis/src/coherence/builtin.rs @@ -389,7 +389,7 @@ pub fn coerce_unsized_info<'tcx>(tcx: TyCtxt<'tcx>, impl_did: DefId) -> CoerceUn let check_mutbl = |mt_a: ty::TypeAndMut<'tcx>, mt_b: ty::TypeAndMut<'tcx>, mk_ptr: &dyn Fn(Ty<'tcx>) -> Ty<'tcx>| { - if mt_a.mutbl < mt_b.mutbl { + if let (hir::Mutability::Not, hir::Mutability::Mut) = (mt_a.mutbl, mt_b.mutbl) { infcx .err_ctxt() .report_mismatched_types( diff --git a/compiler/rustc_hir_analysis/src/outlives/utils.rs b/compiler/rustc_hir_analysis/src/outlives/utils.rs index c5c5f63a108b3..8490fc199e226 100644 --- a/compiler/rustc_hir_analysis/src/outlives/utils.rs +++ b/compiler/rustc_hir_analysis/src/outlives/utils.rs @@ -1,14 +1,14 @@ +use rustc_data_structures::fx::FxHashMap; use rustc_infer::infer::outlives::components::{push_outlives_components, Component}; use rustc_middle::ty::subst::{GenericArg, GenericArgKind}; use rustc_middle::ty::{self, Region, Ty, TyCtxt}; use rustc_span::Span; use smallvec::smallvec; -use std::collections::BTreeMap; /// Tracks the `T: 'a` or `'a: 'a` predicates that we have inferred /// must be added to the struct header. pub(crate) type RequiredPredicates<'tcx> = - BTreeMap, ty::Region<'tcx>>, Span>; + FxHashMap, ty::Region<'tcx>>, Span>; /// Given a requirement `T: 'a` or `'b: 'a`, deduce the /// outlives_component and add it to `required_predicates` diff --git a/compiler/rustc_hir_typeck/src/_match.rs b/compiler/rustc_hir_typeck/src/_match.rs index e19ef2ff3bf48..4f4d2aa0c5540 100644 --- a/compiler/rustc_hir_typeck/src/_match.rs +++ b/compiler/rustc_hir_typeck/src/_match.rs @@ -575,5 +575,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } fn arms_contain_ref_bindings<'tcx>(arms: &'tcx [hir::Arm<'tcx>]) -> Option { - arms.iter().filter_map(|a| a.pat.contains_explicit_ref_binding()).max() + arms.iter().filter_map(|a| a.pat.contains_explicit_ref_binding()).max_by_key(|m| match m { + hir::Mutability::Not => 0u8, + hir::Mutability::Mut => 1, + }) } diff --git a/compiler/rustc_hir_typeck/src/cast.rs b/compiler/rustc_hir_typeck/src/cast.rs index 8e21c084841d0..586625a027482 100644 --- a/compiler/rustc_hir_typeck/src/cast.rs +++ b/compiler/rustc_hir_typeck/src/cast.rs @@ -947,7 +947,7 @@ impl<'a, 'tcx> CastCheck<'tcx> { m_cast: ty::TypeAndMut<'tcx>, ) -> Result { // array-ptr-cast: allow mut-to-mut, mut-to-const, const-to-const - if m_expr.mutbl >= m_cast.mutbl { + if m_expr.mutbl == m_cast.mutbl || m_expr.mutbl == hir::Mutability::Mut { if let ty::Array(ety, _) = m_expr.ty.kind() { // Due to the limitations of LLVM global constants, // region pointers end up pointing at copies of diff --git a/compiler/rustc_hir_typeck/src/coercion.rs b/compiler/rustc_hir_typeck/src/coercion.rs index 7173239ba619a..f3981423cb4e1 100644 --- a/compiler/rustc_hir_typeck/src/coercion.rs +++ b/compiler/rustc_hir_typeck/src/coercion.rs @@ -110,7 +110,11 @@ fn coerce_mutbls<'tcx>( from_mutbl: hir::Mutability, to_mutbl: hir::Mutability, ) -> RelateResult<'tcx, ()> { - if from_mutbl >= to_mutbl { Ok(()) } else { Err(TypeError::Mutability) } + if from_mutbl == to_mutbl || from_mutbl == hir::Mutability::Mut { + Ok(()) + } else { + Err(TypeError::Mutability) + } } /// Do not require any adjustments, i.e. coerce `x -> x`. diff --git a/compiler/rustc_hir_typeck/src/demand.rs b/compiler/rustc_hir_typeck/src/demand.rs index ae00042eae73d..41af70a87c2d6 100644 --- a/compiler/rustc_hir_typeck/src/demand.rs +++ b/compiler/rustc_hir_typeck/src/demand.rs @@ -1420,7 +1420,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ( sp, format!("{}{derefs}", if mutbl_a != mutbl_b { mutbl_b.prefix_str() } else { "" }), - if mutbl_b <= mutbl_a { Applicability::MachineApplicable } else { Applicability::MaybeIncorrect } + if mutbl_b == mutbl_a || mutbl_b == hir::Mutability::Not { Applicability::MachineApplicable } else { Applicability::MaybeIncorrect } ) }); diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs index 54890489f8b8f..2685f369566e0 100644 --- a/compiler/rustc_hir_typeck/src/method/suggest.rs +++ b/compiler/rustc_hir_typeck/src/method/suggest.rs @@ -1936,7 +1936,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { _ => None, }) .collect(); - preds.sort_by_key(|pred| (pred.def_id(), pred.self_ty())); + preds.sort_by_key(|pred| pred.def_id()); let def_ids = preds .iter() .filter_map(|pred| match pred.self_ty().kind() { diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_error.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_error.rs index 99431567edac4..7c0d900abe3e5 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_error.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_error.rs @@ -60,6 +60,7 @@ impl<'tcx> NiceRegionError<'_, 'tcx> { pub(super) fn try_report_placeholder_conflict( &self, ) -> Option> { + debug!(?self.error, "try_report_placeholder_conflict"); match &self.error { /////////////////////////////////////////////////////////////////////////// // NB. The ordering of cases in this match is very diff --git a/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs b/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs index 4a2210bdb68d0..8ccd5fc7698f9 100644 --- a/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs +++ b/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs @@ -238,8 +238,14 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> { // later use this to expand across vids. let mut constraints = IndexVec::from_elem_n(Vec::new(), var_values.values.len()); // Tracks the changed region vids. - let mut changes = Vec::new(); - for constraint in self.data.constraints.keys() { + let mut changes = vec![]; + let mut input_constraints: Vec<_> = self.data.constraints.keys().collect(); + input_constraints.sort_by_key(|c| match c { + Constraint::VarSubVar(..) => 0u8, + Constraint::RegSubVar(..) => 1, + Constraint::VarSubReg(..) | Constraint::RegSubReg(..) => 2, + }); + for constraint in input_constraints { match *constraint { Constraint::RegSubVar(a_region, b_vid) => { let b_data = var_values.value_mut(b_vid); diff --git a/compiler/rustc_infer/src/infer/region_constraints/mod.rs b/compiler/rustc_infer/src/infer/region_constraints/mod.rs index cb24375c7a3fe..3729b6c544f09 100644 --- a/compiler/rustc_infer/src/infer/region_constraints/mod.rs +++ b/compiler/rustc_infer/src/infer/region_constraints/mod.rs @@ -7,7 +7,9 @@ use super::{ InferCtxtUndoLogs, MiscVariable, RegionVariableOrigin, Rollback, Snapshot, SubregionOrigin, }; -use rustc_data_structures::fx::{FxHashMap, FxIndexSet}; +use rustc_data_structures::fx::FxHashMap; +use rustc_data_structures::fx::FxIndexMap; +use rustc_data_structures::fx::FxIndexSet; use rustc_data_structures::intern::Interned; use rustc_data_structures::sync::Lrc; use rustc_data_structures::undo_log::UndoLogs; @@ -20,7 +22,6 @@ use rustc_middle::ty::{ReLateBound, ReVar}; use rustc_middle::ty::{Region, RegionVid}; use rustc_span::Span; -use std::collections::BTreeMap; use std::ops::Range; use std::{cmp, fmt, mem}; @@ -90,7 +91,7 @@ pub type VarInfos = IndexVec; pub struct RegionConstraintData<'tcx> { /// Constraints of the form `A <= B`, where either `A` or `B` can /// be a region variable (or neither, as it happens). - pub constraints: BTreeMap, SubregionOrigin<'tcx>>, + pub constraints: FxIndexMap, SubregionOrigin<'tcx>>, /// Constraints of the form `R0 member of [R1, ..., Rn]`, meaning that /// `R0` must be equal to one of the regions `R1..Rn`. These occur @@ -127,7 +128,7 @@ pub struct RegionConstraintData<'tcx> { } /// Represents a constraint that influences the inference process. -#[derive(Clone, Copy, PartialEq, Eq, Debug, PartialOrd, Ord)] +#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)] pub enum Constraint<'tcx> { /// A region variable is a subregion of another. VarSubVar(RegionVid, RegionVid), diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index f18c0aa377fb4..c9ef74850ebac 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -1200,7 +1200,7 @@ impl<'tcx> LateLintPass<'tcx> for MutableTransmutes { if let Some((&ty::Ref(_, _, from_mutbl), &ty::Ref(_, _, to_mutbl))) = get_transmute_from_to(cx, expr).map(|(ty1, ty2)| (ty1.kind(), ty2.kind())) { - if from_mutbl < to_mutbl { + if let (hir::Mutability::Not, hir::Mutability::Mut) = (from_mutbl, to_mutbl) { cx.emit_spanned_lint(MUTABLE_TRANSMUTES, expr.span, BuiltinMutablesTransmutes); } } diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index 6996d91a80dcc..b8fc41d13ebe7 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -2580,7 +2580,7 @@ impl<'tcx> ConstantKind<'tcx> { } /// An unevaluated (potentially generic) constant used in MIR. -#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, TyEncodable, TyDecodable, Lift)] +#[derive(Copy, Clone, Debug, Eq, PartialEq, TyEncodable, TyDecodable, Lift)] #[derive(Hash, HashStable, TypeFoldable, TypeVisitable)] pub struct UnevaluatedConst<'tcx> { pub def: ty::WithOptConstParam, diff --git a/compiler/rustc_middle/src/mir/query.rs b/compiler/rustc_middle/src/mir/query.rs index e2ab3fd35b331..e70bbedd9b980 100644 --- a/compiler/rustc_middle/src/mir/query.rs +++ b/compiler/rustc_middle/src/mir/query.rs @@ -17,6 +17,8 @@ use std::fmt::{self, Debug}; use super::{Field, SourceInfo}; +mod order; + #[derive(Copy, Clone, PartialEq, TyEncodable, TyDecodable, HashStable, Debug)] pub enum UnsafetyViolationKind { /// Unsafe operation outside `unsafe`. @@ -336,7 +338,7 @@ rustc_data_structures::static_assert_size!(ConstraintCategory<'_>, 16); /// order of the category, thereby influencing diagnostic output. /// /// See also `rustc_const_eval::borrow_check::constraints`. -#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)] +#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] #[derive(TyEncodable, TyDecodable, HashStable, Lift, TypeVisitable, TypeFoldable)] pub enum ConstraintCategory<'tcx> { Return(ReturnConstraint), diff --git a/compiler/rustc_middle/src/mir/query/order.rs b/compiler/rustc_middle/src/mir/query/order.rs new file mode 100644 index 0000000000000..29096096b105d --- /dev/null +++ b/compiler/rustc_middle/src/mir/query/order.rs @@ -0,0 +1,27 @@ +use super::ConstraintCategory; + +impl<'tcx> ConstraintCategory<'tcx> { + pub fn cmp_discr(&self) -> u8 { + use ConstraintCategory::*; + match self { + Return(_) => 0, + Yield => 1, + UseAsConst => 2, + UseAsStatic => 3, + TypeAnnotation => 4, + Cast => 5, + ClosureBounds => 6, + CallArgument(_) => 7, + CopyBound => 8, + SizedBound => 9, + Assignment => 10, + Usage => 11, + OpaqueType => 12, + ClosureUpvar(_) => 13, + Predicate(_) => 14, + Boring => 15, + BoringNoLocation => 16, + Internal => 17, + } + } +} diff --git a/compiler/rustc_middle/src/ty/consts.rs b/compiler/rustc_middle/src/ty/consts.rs index 3ad56e8f273df..714c3b0c7432d 100644 --- a/compiler/rustc_middle/src/ty/consts.rs +++ b/compiler/rustc_middle/src/ty/consts.rs @@ -15,7 +15,7 @@ pub use kind::*; pub use valtree::*; /// Use this rather than `ConstData, whenever possible. -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, HashStable)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, HashStable)] #[rustc_pass_by_value] pub struct Const<'tcx>(pub(super) Interned<'tcx, ConstData<'tcx>>); @@ -29,7 +29,7 @@ impl<'tcx> fmt::Debug for Const<'tcx> { } /// Typed constant value. -#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, HashStable, TyEncodable, TyDecodable)] +#[derive(PartialEq, Eq, Hash, HashStable, TyEncodable, TyDecodable)] pub struct ConstData<'tcx> { pub ty: Ty<'tcx>, pub kind: ConstKind<'tcx>, diff --git a/compiler/rustc_middle/src/ty/consts/kind.rs b/compiler/rustc_middle/src/ty/consts/kind.rs index d9721863a58c8..962197b4b0252 100644 --- a/compiler/rustc_middle/src/ty/consts/kind.rs +++ b/compiler/rustc_middle/src/ty/consts/kind.rs @@ -14,7 +14,7 @@ use rustc_target::abi::Size; use super::ScalarInt; /// An unevaluated (potentially generic) constant used in the type-system. -#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, TyEncodable, TyDecodable, Lift)] +#[derive(Copy, Clone, Debug, Eq, PartialEq, TyEncodable, TyDecodable, Lift)] #[derive(Hash, HashStable, TypeFoldable, TypeVisitable)] pub struct UnevaluatedConst<'tcx> { pub def: ty::WithOptConstParam, @@ -45,7 +45,7 @@ impl<'tcx> UnevaluatedConst<'tcx> { } /// Represents a constant in Rust. -#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, TyEncodable, TyDecodable)] +#[derive(Copy, Clone, Debug, Eq, PartialEq, TyEncodable, TyDecodable)] #[derive(Hash, HashStable, TypeFoldable, TypeVisitable)] #[derive(derive_more::From)] pub enum ConstKind<'tcx> { @@ -83,7 +83,7 @@ impl<'tcx> From> for ConstKind<'tcx> { } } -#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)] +#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] #[derive(HashStable, TyEncodable, TyDecodable, TypeVisitable, TypeFoldable)] pub enum Expr<'tcx> { Binop(mir::BinOp, Const<'tcx>, Const<'tcx>), @@ -131,7 +131,7 @@ impl<'tcx> ConstKind<'tcx> { } /// An inference variable for a const, for use in const generics. -#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, TyEncodable, TyDecodable, Hash)] +#[derive(Copy, Clone, Debug, Eq, PartialEq, TyEncodable, TyDecodable, Hash)] pub enum InferConst<'tcx> { /// Infer the value of the const. Var(ty::ConstVid<'tcx>), diff --git a/compiler/rustc_middle/src/ty/instance.rs b/compiler/rustc_middle/src/ty/instance.rs index 55f2395e531a5..eb7f56456c126 100644 --- a/compiler/rustc_middle/src/ty/instance.rs +++ b/compiler/rustc_middle/src/ty/instance.rs @@ -25,7 +25,7 @@ pub struct Instance<'tcx> { pub substs: SubstsRef<'tcx>, } -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] #[derive(TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable, Lift)] pub enum InstanceDef<'tcx> { /// A user-defined callable item. diff --git a/compiler/rustc_middle/src/ty/list.rs b/compiler/rustc_middle/src/ty/list.rs index 79365ef281be7..77c43435ecde2 100644 --- a/compiler/rustc_middle/src/ty/list.rs +++ b/compiler/rustc_middle/src/ty/list.rs @@ -1,7 +1,6 @@ use crate::arena::Arena; use rustc_serialize::{Encodable, Encoder}; use std::alloc::Layout; -use std::cmp::Ordering; use std::fmt; use std::hash::{Hash, Hasher}; use std::iter; @@ -137,32 +136,6 @@ impl PartialEq for List { impl Eq for List {} -impl Ord for List -where - T: Ord, -{ - fn cmp(&self, other: &List) -> Ordering { - // Pointer equality implies list equality (due to the unique contents - // assumption), but the contents must be compared otherwise. - if self == other { Ordering::Equal } else { <[T] as Ord>::cmp(&**self, &**other) } - } -} - -impl PartialOrd for List -where - T: PartialOrd, -{ - fn partial_cmp(&self, other: &List) -> Option { - // Pointer equality implies list equality (due to the unique contents - // assumption), but the contents must be compared otherwise. - if self == other { - Some(Ordering::Equal) - } else { - <[T] as PartialOrd>::partial_cmp(&**self, &**other) - } - } -} - impl Hash for List { #[inline] fn hash(&self, s: &mut H) { diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 5b7ca750f78fb..b5887d7b32c95 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -454,7 +454,7 @@ pub struct CReaderCacheKey { } /// Use this rather than `TyKind`, whenever possible. -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, HashStable)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, HashStable)] #[rustc_diagnostic_item = "Ty"] #[rustc_pass_by_value] pub struct Ty<'tcx>(Interned<'tcx, WithCachedTypeInfo>>); @@ -852,7 +852,7 @@ impl<'tcx> PolyTraitPredicate<'tcx> { } /// `A: B` -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, TyEncodable, TyDecodable)] +#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, TyEncodable, TyDecodable)] #[derive(HashStable, TypeFoldable, TypeVisitable, Lift)] pub struct OutlivesPredicate(pub A, pub B); pub type RegionOutlivesPredicate<'tcx> = OutlivesPredicate, ty::Region<'tcx>>; @@ -881,7 +881,7 @@ pub struct CoercePredicate<'tcx> { } pub type PolyCoercePredicate<'tcx> = ty::Binder<'tcx, CoercePredicate<'tcx>>; -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Clone, Copy, PartialEq, Eq, Hash)] pub struct Term<'tcx> { ptr: NonZeroUsize, marker: PhantomData<(Ty<'tcx>, Const<'tcx>)>, @@ -1010,7 +1010,7 @@ const TAG_MASK: usize = 0b11; const TYPE_TAG: usize = 0b00; const CONST_TAG: usize = 0b01; -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, TyEncodable, TyDecodable)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable)] #[derive(HashStable, TypeFoldable, TypeVisitable)] pub enum TermKind<'tcx> { Ty(Ty<'tcx>), @@ -1404,7 +1404,7 @@ impl<'tcx> OpaqueHiddenType<'tcx> { /// identified by both a universe, as well as a name residing within that universe. Distinct bound /// regions/types/consts within the same universe simply have an unknown relationship to one /// another. -#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] #[derive(HashStable, TyEncodable, TyDecodable)] pub struct Placeholder { pub universe: UniverseIndex, @@ -1416,7 +1416,7 @@ pub type PlaceholderRegion = Placeholder; pub type PlaceholderType = Placeholder; #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, HashStable)] -#[derive(TyEncodable, TyDecodable, PartialOrd, Ord)] +#[derive(TyEncodable, TyDecodable)] pub struct BoundConst<'tcx> { pub var: BoundVar, pub ty: Ty<'tcx>, @@ -1476,7 +1476,7 @@ pub type PlaceholderConst<'tcx> = Placeholder; /// Meaning that we need to use `type_of(const_param_did)` if `const_param_did` is `Some` /// to get the type of `did`. #[derive(Copy, Clone, Debug, TypeFoldable, TypeVisitable, Lift, TyEncodable, TyDecodable)] -#[derive(PartialEq, Eq, PartialOrd, Ord)] +#[derive(PartialEq, Eq)] #[derive(Hash, HashStable)] pub struct WithOptConstParam { pub did: T, diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index c613b3627f2f6..f065997f27d35 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -42,7 +42,7 @@ use rustc_type_ir::TyKind as IrTyKind; pub type TyKind<'tcx> = IrTyKind>; pub type RegionKind<'tcx> = IrRegionKind>; -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, TyEncodable, TyDecodable)] +#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, TyEncodable, TyDecodable)] #[derive(HashStable, TypeFoldable, TypeVisitable, Lift)] pub struct TypeAndMut<'tcx> { pub ty: Ty<'tcx>, @@ -683,7 +683,7 @@ impl<'tcx> InlineConstSubsts<'tcx> { } } -#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Ord, Eq, Hash, TyEncodable, TyDecodable)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable)] #[derive(HashStable, TypeFoldable, TypeVisitable, Lift)] pub enum ExistentialPredicate<'tcx> { /// E.g., `Iterator`. @@ -820,7 +820,7 @@ impl<'tcx> List> { /// /// Trait references also appear in object types like `Foo`, but in /// that case the `Self` parameter is absent from the substitutions. -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, TyDecodable)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable)] #[derive(HashStable, TypeFoldable, TypeVisitable, Lift)] pub struct TraitRef<'tcx> { pub def_id: DefId, @@ -884,7 +884,7 @@ impl rustc_errors::IntoDiagnosticArg for PolyTraitRef<'_> { /// ``` /// The substitutions don't include the erased `Self`, only trait /// type and lifetime parameters (`[X, Y]` and `['a, 'b]` above). -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, TyDecodable)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable)] #[derive(HashStable, TypeFoldable, TypeVisitable, Lift)] pub struct ExistentialTraitRef<'tcx> { pub def_id: DefId, @@ -933,7 +933,7 @@ impl<'tcx> PolyExistentialTraitRef<'tcx> { } } -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, TyEncodable, TyDecodable)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, TyEncodable, TyDecodable)] #[derive(HashStable)] pub enum BoundVariableKind { Ty(BoundTyKind), @@ -973,7 +973,7 @@ impl BoundVariableKind { /// e.g., `liberate_late_bound_regions`). /// /// `Decodable` and `Encodable` are implemented for `Binder` using the `impl_binder_encode_decode!` macro. -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] #[derive(HashStable, Lift)] pub struct Binder<'tcx, T>(T, &'tcx List); @@ -1224,7 +1224,7 @@ impl<'tcx> FallibleTypeFolder> for SkipBindersAt<'tcx> { /// For a projection, this would be `>::N`. /// /// For an opaque type, there is no explicit syntax. -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, TyDecodable)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable)] #[derive(HashStable, TypeFoldable, TypeVisitable, Lift)] pub struct AliasTy<'tcx> { /// The parameters of the associated or opaque item. @@ -1330,7 +1330,7 @@ pub type PolyGenSig<'tcx> = Binder<'tcx, GenSig<'tcx>>; /// - `inputs`: is the list of arguments and their modes. /// - `output`: is the return type. /// - `c_variadic`: indicates whether this is a C-variadic function. -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, TyDecodable)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable)] #[derive(HashStable, TypeFoldable, TypeVisitable, Lift)] pub struct FnSig<'tcx> { pub inputs_and_output: &'tcx List>, @@ -1437,7 +1437,7 @@ impl ParamConst { } /// Use this rather than `RegionKind`, whenever possible. -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, HashStable)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, HashStable)] #[rustc_pass_by_value] pub struct Region<'tcx>(pub Interned<'tcx, RegionKind<'tcx>>); @@ -1526,7 +1526,7 @@ impl From for BoundTy { } /// A `ProjectionPredicate` for an `ExistentialTraitRef`. -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, TyEncodable, TyDecodable)] +#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, TyEncodable, TyDecodable)] #[derive(HashStable, TypeFoldable, TypeVisitable, Lift)] pub struct ExistentialProjection<'tcx> { pub def_id: DefId, @@ -2456,7 +2456,7 @@ impl<'tcx> Ty<'tcx> { /// a miscompilation or unsoundness. /// /// When in doubt, use `VarianceDiagInfo::default()` -#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)] pub enum VarianceDiagInfo<'tcx> { /// No additional information - this is the default. /// We will not add any additional information to error messages. diff --git a/compiler/rustc_middle/src/ty/subst.rs b/compiler/rustc_middle/src/ty/subst.rs index a6ab7440c8e66..b196545f47f88 100644 --- a/compiler/rustc_middle/src/ty/subst.rs +++ b/compiler/rustc_middle/src/ty/subst.rs @@ -15,7 +15,6 @@ use rustc_type_ir::WithCachedTypeInfo; use smallvec::SmallVec; use core::intrinsics; -use std::cmp::Ordering; use std::fmt; use std::marker::PhantomData; use std::mem; @@ -48,7 +47,7 @@ const TYPE_TAG: usize = 0b00; const REGION_TAG: usize = 0b01; const CONST_TAG: usize = 0b10; -#[derive(Debug, TyEncodable, TyDecodable, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Debug, TyEncodable, TyDecodable, PartialEq, Eq)] pub enum GenericArgKind<'tcx> { Lifetime(ty::Region<'tcx>), Type(Ty<'tcx>), @@ -115,18 +114,6 @@ impl<'tcx> fmt::Debug for GenericArg<'tcx> { } } -impl<'tcx> Ord for GenericArg<'tcx> { - fn cmp(&self, other: &GenericArg<'tcx>) -> Ordering { - self.unpack().cmp(&other.unpack()) - } -} - -impl<'tcx> PartialOrd for GenericArg<'tcx> { - fn partial_cmp(&self, other: &GenericArg<'tcx>) -> Option { - Some(self.cmp(&other)) - } -} - impl<'tcx> From> for GenericArg<'tcx> { #[inline] fn from(r: ty::Region<'tcx>) -> GenericArg<'tcx> { @@ -552,7 +539,7 @@ impl<'tcx, T: TypeVisitable<'tcx>> ir::TypeVisitable> for &'tcx ty: /// /// If you don't have anything to `subst`, you may be looking for /// [`subst_identity`](EarlyBinder::subst_identity) or [`skip_binder`](EarlyBinder::skip_binder). -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] #[derive(Encodable, Decodable, HashStable)] pub struct EarlyBinder(pub T); diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs index c2565b7a3aa3e..f7903ba3c25cd 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -17,7 +17,7 @@ use crate::traits::specialize::to_pretty_impl_header; use crate::traits::NormalizeExt; use on_unimplemented::OnUnimplementedNote; use on_unimplemented::TypeErrCtxtExt as _; -use rustc_data_structures::fx::{FxHashMap, FxIndexMap}; +use rustc_data_structures::fx::{FxHashMap, FxIndexMap, FxIndexSet}; use rustc_errors::{ pluralize, struct_span_err, Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, MultiSpan, Style, @@ -55,7 +55,7 @@ pub use rustc_infer::traits::error_reporting::*; // // We also compare candidates after skipping lifetimes, which has a lower // priority than exact matches. -#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum CandidateSimilarity { Exact { ignoring_lifetimes: bool }, Fuzzy { ignoring_lifetimes: bool }, @@ -2026,13 +2026,13 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { other: bool, ) -> bool { let other = if other { "other " } else { "" }; - let report = |mut candidates: Vec>, err: &mut Diagnostic| { - candidates.sort(); - candidates.dedup(); - let len = candidates.len(); + let report = |candidates: Vec>, err: &mut Diagnostic| { if candidates.is_empty() { return false; } + let candidates = FxIndexSet::from_iter(candidates); + let len = candidates.len(); + let candidates = Vec::from_iter(candidates); if let &[cand] = &candidates[..] { let (desc, mention_castable) = match (cand.self_ty().kind(), trait_ref.self_ty().skip_binder().kind()) { @@ -2129,7 +2129,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { // // Prefer more similar candidates first, then sort lexicographically // by their normalized string representation. - let mut normalized_impl_candidates_and_similarities = impl_candidates + let normalized_impl_candidates_and_similarities = impl_candidates .into_iter() .map(|ImplCandidate { trait_ref, similarity }| { // FIXME(compiler-errors): This should be using `NormalizeExt::normalize` @@ -2139,9 +2139,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { .map_or(trait_ref, |normalized| normalized.value); (similarity, normalized) }) - .collect::>(); - normalized_impl_candidates_and_similarities.sort(); - normalized_impl_candidates_and_similarities.dedup(); + .collect::>(); let normalized_impl_candidates = normalized_impl_candidates_and_similarities .into_iter() diff --git a/compiler/rustc_trait_selection/src/traits/project.rs b/compiler/rustc_trait_selection/src/traits/project.rs index a380d4697ea26..f75062aff25cc 100644 --- a/compiler/rustc_trait_selection/src/traits/project.rs +++ b/compiler/rustc_trait_selection/src/traits/project.rs @@ -21,6 +21,7 @@ use crate::infer::{InferCtxt, InferOk, LateBoundRegionConversionTime}; use crate::traits::error_reporting::TypeErrCtxtExt as _; use crate::traits::query::evaluate_obligation::InferCtxtExt as _; use crate::traits::select::ProjectionMatchesProjection; +use rustc_data_structures::fx::FxIndexMap; use rustc_data_structures::sso::SsoHashSet; use rustc_data_structures::stack::ensure_sufficient_stack; use rustc_errors::ErrorGuaranteed; @@ -36,8 +37,6 @@ use rustc_middle::ty::DefIdTree; use rustc_middle::ty::{self, Term, ToPredicate, Ty, TyCtxt}; use rustc_span::symbol::sym; -use std::collections::BTreeMap; - pub use rustc_middle::traits::Reveal; pub type PolyProjectionObligation<'tcx> = Obligation<'tcx, ty::PolyProjectionPredicate<'tcx>>; @@ -649,9 +648,9 @@ pub struct BoundVarReplacer<'me, 'tcx> { // These three maps track the bound variable that were replaced by placeholders. It might be // nice to remove these since we already have the `kind` in the placeholder; we really just need // the `var` (but we *could* bring that into scope if we were to track them as we pass them). - mapped_regions: BTreeMap, - mapped_types: BTreeMap, - mapped_consts: BTreeMap, ty::BoundVar>, + mapped_regions: FxIndexMap, + mapped_types: FxIndexMap, + mapped_consts: FxIndexMap, ty::BoundVar>, // The current depth relative to *this* folding, *not* the entire normalization. In other words, // the depth of binders we've passed here. current_index: ty::DebruijnIndex, @@ -704,19 +703,15 @@ impl<'me, 'tcx> BoundVarReplacer<'me, 'tcx> { value: T, ) -> ( T, - BTreeMap, - BTreeMap, - BTreeMap, ty::BoundVar>, + FxIndexMap, + FxIndexMap, + FxIndexMap, ty::BoundVar>, ) { - let mapped_regions: BTreeMap = BTreeMap::new(); - let mapped_types: BTreeMap = BTreeMap::new(); - let mapped_consts: BTreeMap, ty::BoundVar> = BTreeMap::new(); - let mut replacer = BoundVarReplacer { infcx, - mapped_regions, - mapped_types, - mapped_consts, + mapped_regions: <_>::default(), + mapped_types: <_>::default(), + mapped_consts: <_>::default(), current_index: ty::INNERMOST, universe_indices, }; @@ -818,9 +813,9 @@ impl<'tcx> TypeFolder> for BoundVarReplacer<'_, 'tcx> { /// The inverse of [`BoundVarReplacer`]: replaces placeholders with the bound vars from which they came. pub struct PlaceholderReplacer<'me, 'tcx> { infcx: &'me InferCtxt<'tcx>, - mapped_regions: BTreeMap, - mapped_types: BTreeMap, - mapped_consts: BTreeMap, ty::BoundVar>, + mapped_regions: FxIndexMap, + mapped_types: FxIndexMap, + mapped_consts: FxIndexMap, ty::BoundVar>, universe_indices: &'me [Option], current_index: ty::DebruijnIndex, } @@ -828,9 +823,9 @@ pub struct PlaceholderReplacer<'me, 'tcx> { impl<'me, 'tcx> PlaceholderReplacer<'me, 'tcx> { pub fn replace_placeholders>( infcx: &'me InferCtxt<'tcx>, - mapped_regions: BTreeMap, - mapped_types: BTreeMap, - mapped_consts: BTreeMap, ty::BoundVar>, + mapped_regions: FxIndexMap, + mapped_types: FxIndexMap, + mapped_consts: FxIndexMap, ty::BoundVar>, universe_indices: &'me [Option], value: T, ) -> T { diff --git a/compiler/rustc_transmute/src/layout/mod.rs b/compiler/rustc_transmute/src/layout/mod.rs index f8d05bc89d26d..4afea57760e94 100644 --- a/compiler/rustc_transmute/src/layout/mod.rs +++ b/compiler/rustc_transmute/src/layout/mod.rs @@ -43,7 +43,7 @@ pub(crate) mod rustc { use rustc_middle::ty::Ty; /// A reference in the layout. - #[derive(Debug, Hash, Eq, PartialEq, PartialOrd, Ord, Clone, Copy)] + #[derive(Debug, Hash, Eq, PartialEq, Clone, Copy)] pub struct Ref<'tcx> { lifetime: Region<'tcx>, ty: Ty<'tcx>, diff --git a/compiler/rustc_type_ir/src/lib.rs b/compiler/rustc_type_ir/src/lib.rs index cb28731681ba0..3c66d7da3066d 100644 --- a/compiler/rustc_type_ir/src/lib.rs +++ b/compiler/rustc_type_ir/src/lib.rs @@ -38,35 +38,35 @@ pub use ty_info::*; pub trait HashStableContext {} pub trait Interner: Sized { - type AdtDef: Clone + Debug + Hash + Ord; - type SubstsRef: Clone + Debug + Hash + Ord; - type DefId: Clone + Debug + Hash + Ord; + type AdtDef: Clone + Debug + Hash + Eq; + type SubstsRef: Clone + Debug + Hash + Eq; + type DefId: Clone + Debug + Hash + Eq; type Binder; - type Ty: Clone + Debug + Hash + Ord; - type Const: Clone + Debug + Hash + Ord; - type Region: Clone + Debug + Hash + Ord; + type Ty: Clone + Debug + Hash + Eq; + type Const: Clone + Debug + Hash + Eq; + type Region: Clone + Debug + Hash + Eq; type Predicate; - type TypeAndMut: Clone + Debug + Hash + Ord; - type Mutability: Clone + Debug + Hash + Ord; - type Movability: Clone + Debug + Hash + Ord; - type PolyFnSig: Clone + Debug + Hash + Ord; - type ListBinderExistentialPredicate: Clone + Debug + Hash + Ord; - type BinderListTy: Clone + Debug + Hash + Ord; - type ListTy: Clone + Debug + Hash + Ord; - type AliasTy: Clone + Debug + Hash + Ord; - type ParamTy: Clone + Debug + Hash + Ord; - type BoundTy: Clone + Debug + Hash + Ord; - type PlaceholderType: Clone + Debug + Hash + Ord; - type InferTy: Clone + Debug + Hash + Ord; - type ErrorGuaranteed: Clone + Debug + Hash + Ord; + type TypeAndMut: Clone + Debug + Hash + Eq; + type Mutability: Clone + Debug + Hash + Eq; + type Movability: Clone + Debug + Hash + Eq; + type PolyFnSig: Clone + Debug + Hash + Eq; + type ListBinderExistentialPredicate: Clone + Debug + Hash + Eq; + type BinderListTy: Clone + Debug + Hash + Eq; + type ListTy: Clone + Debug + Hash + Eq; + type AliasTy: Clone + Debug + Hash + Eq; + type ParamTy: Clone + Debug + Hash + Eq; + type BoundTy: Clone + Debug + Hash + Eq; + type PlaceholderType: Clone + Debug + Hash + PartialEq + Eq; + type InferTy: Clone + Debug + Hash + Eq; + type ErrorGuaranteed: Clone + Debug + Hash + Eq; type PredicateKind: Clone + Debug + Hash + PartialEq + Eq; - type AllocId: Clone + Debug + Hash + Ord; + type AllocId: Clone + Debug + Hash + Eq; - type EarlyBoundRegion: Clone + Debug + Hash + Ord; - type BoundRegion: Clone + Debug + Hash + Ord; - type FreeRegion: Clone + Debug + Hash + Ord; - type RegionVid: Clone + Debug + Hash + Ord; - type PlaceholderRegion: Clone + Debug + Hash + Ord; + type EarlyBoundRegion: Clone + Debug + Hash + PartialEq + Eq; + type BoundRegion: Clone + Debug + Hash + PartialEq + Eq; + type FreeRegion: Clone + Debug + Hash + PartialEq + Eq; + type RegionVid: Clone + Debug + Hash + PartialEq + Eq; + type PlaceholderRegion: Clone + Debug + Hash + PartialEq + Eq; } pub trait InternAs { diff --git a/compiler/rustc_type_ir/src/sty.rs b/compiler/rustc_type_ir/src/sty.rs index 61557fdc0eda4..b3e8642138128 100644 --- a/compiler/rustc_type_ir/src/sty.rs +++ b/compiler/rustc_type_ir/src/sty.rs @@ -1,6 +1,5 @@ #![allow(rustc::usage_of_ty_tykind)] -use std::cmp::Ordering; use std::{fmt, hash}; use crate::DebruijnIndex; @@ -361,65 +360,6 @@ impl PartialEq for TyKind { // This is manually implemented because a derive would require `I: Eq` impl Eq for TyKind {} -// This is manually implemented because a derive would require `I: PartialOrd` -impl PartialOrd for TyKind { - #[inline] - fn partial_cmp(&self, other: &TyKind) -> Option { - Some(self.cmp(other)) - } -} - -// This is manually implemented because a derive would require `I: Ord` -impl Ord for TyKind { - #[inline] - fn cmp(&self, other: &TyKind) -> Ordering { - tykind_discriminant(self).cmp(&tykind_discriminant(other)).then_with(|| { - match (self, other) { - (Int(a_i), Int(b_i)) => a_i.cmp(b_i), - (Uint(a_u), Uint(b_u)) => a_u.cmp(b_u), - (Float(a_f), Float(b_f)) => a_f.cmp(b_f), - (Adt(a_d, a_s), Adt(b_d, b_s)) => a_d.cmp(b_d).then_with(|| a_s.cmp(b_s)), - (Foreign(a_d), Foreign(b_d)) => a_d.cmp(b_d), - (Array(a_t, a_c), Array(b_t, b_c)) => a_t.cmp(b_t).then_with(|| a_c.cmp(b_c)), - (Slice(a_t), Slice(b_t)) => a_t.cmp(b_t), - (RawPtr(a_t), RawPtr(b_t)) => a_t.cmp(b_t), - (Ref(a_r, a_t, a_m), Ref(b_r, b_t, b_m)) => { - a_r.cmp(b_r).then_with(|| a_t.cmp(b_t).then_with(|| a_m.cmp(b_m))) - } - (FnDef(a_d, a_s), FnDef(b_d, b_s)) => a_d.cmp(b_d).then_with(|| a_s.cmp(b_s)), - (FnPtr(a_s), FnPtr(b_s)) => a_s.cmp(b_s), - (Dynamic(a_p, a_r, a_repr), Dynamic(b_p, b_r, b_repr)) => { - a_p.cmp(b_p).then_with(|| a_r.cmp(b_r).then_with(|| a_repr.cmp(b_repr))) - } - (Closure(a_p, a_s), Closure(b_p, b_s)) => a_p.cmp(b_p).then_with(|| a_s.cmp(b_s)), - (Generator(a_d, a_s, a_m), Generator(b_d, b_s, b_m)) => { - a_d.cmp(b_d).then_with(|| a_s.cmp(b_s).then_with(|| a_m.cmp(b_m))) - } - (GeneratorWitness(a_g), GeneratorWitness(b_g)) => a_g.cmp(b_g), - ( - &GeneratorWitnessMIR(ref a_d, ref a_s), - &GeneratorWitnessMIR(ref b_d, ref b_s), - ) => match Ord::cmp(a_d, b_d) { - Ordering::Equal => Ord::cmp(a_s, b_s), - cmp => cmp, - }, - (Tuple(a_t), Tuple(b_t)) => a_t.cmp(b_t), - (Alias(a_i, a_p), Alias(b_i, b_p)) => a_i.cmp(b_i).then_with(|| a_p.cmp(b_p)), - (Param(a_p), Param(b_p)) => a_p.cmp(b_p), - (Bound(a_d, a_b), Bound(b_d, b_b)) => a_d.cmp(b_d).then_with(|| a_b.cmp(b_b)), - (Placeholder(a_p), Placeholder(b_p)) => a_p.cmp(b_p), - (Infer(a_t), Infer(b_t)) => a_t.cmp(b_t), - (Error(a_e), Error(b_e)) => a_e.cmp(b_e), - (Bool, Bool) | (Char, Char) | (Str, Str) | (Never, Never) => Ordering::Equal, - _ => { - debug_assert!(false, "This branch must be unreachable, maybe the match is missing an arm? self = {self:?}, other = {other:?}"); - Ordering::Equal - } - } - }) - } -} - // This is manually implemented because a derive would require `I: Hash` impl hash::Hash for TyKind { fn hash<__H: hash::Hasher>(&self, state: &mut __H) -> () { @@ -1037,38 +977,6 @@ impl PartialEq for RegionKind { // This is manually implemented because a derive would require `I: Eq` impl Eq for RegionKind {} -// This is manually implemented because a derive would require `I: PartialOrd` -impl PartialOrd for RegionKind { - #[inline] - fn partial_cmp(&self, other: &RegionKind) -> Option { - Some(self.cmp(other)) - } -} - -// This is manually implemented because a derive would require `I: Ord` -impl Ord for RegionKind { - #[inline] - fn cmp(&self, other: &RegionKind) -> Ordering { - regionkind_discriminant(self).cmp(®ionkind_discriminant(other)).then_with(|| { - match (self, other) { - (ReEarlyBound(a_r), ReEarlyBound(b_r)) => a_r.cmp(b_r), - (ReLateBound(a_d, a_r), ReLateBound(b_d, b_r)) => { - a_d.cmp(b_d).then_with(|| a_r.cmp(b_r)) - } - (ReFree(a_r), ReFree(b_r)) => a_r.cmp(b_r), - (ReStatic, ReStatic) => Ordering::Equal, - (ReVar(a_r), ReVar(b_r)) => a_r.cmp(b_r), - (RePlaceholder(a_r), RePlaceholder(b_r)) => a_r.cmp(b_r), - (ReErased, ReErased) => Ordering::Equal, - _ => { - debug_assert!(false, "This branch must be unreachable, maybe the match is missing an arm? self = self = {self:?}, other = {other:?}"); - Ordering::Equal - } - } - }) - } -} - // This is manually implemented because a derive would require `I: Hash` impl hash::Hash for RegionKind { fn hash(&self, state: &mut H) -> () { diff --git a/tests/ui/async-await/issues/issue-72312.stderr b/tests/ui/async-await/issues/issue-72312.stderr index aa947b6900366..5e5a980adb9f2 100644 --- a/tests/ui/async-await/issues/issue-72312.stderr +++ b/tests/ui/async-await/issues/issue-72312.stderr @@ -1,5 +1,5 @@ error[E0521]: borrowed data escapes outside of associated function - --> $DIR/issue-72312.rs:12:9 + --> $DIR/issue-72312.rs:12:24 | LL | pub async fn start(&self) { | ----- @@ -7,16 +7,17 @@ LL | pub async fn start(&self) { | `self` is a reference that is only valid in the associated function body | let's call the lifetime of this reference `'1` ... -LL | / require_static(async move { +LL | require_static(async move { + | ________________________^ LL | | LL | | LL | | LL | | &self; LL | | }); - | | ^ - | | | - | |__________`self` escapes the associated function body here - | argument requires that `'1` must outlive `'static` + | | ^ + | | | + | |_________`self` escapes the associated function body here + | argument requires that `'1` must outlive `'static` error: aborting due to previous error diff --git a/tests/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-comparing-against-free.stderr b/tests/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-comparing-against-free.stderr index 721cd45ded98e..ac1d3bb72b91e 100644 --- a/tests/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-comparing-against-free.stderr +++ b/tests/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-comparing-against-free.stderr @@ -53,17 +53,16 @@ LL | fn case2() { error[E0597]: `a` does not live long enough --> $DIR/propagate-approximated-shorter-to-static-comparing-against-free.rs:30:26 | -LL | let a = 0; - | - binding `a` declared here -LL | let cell = Cell::new(&a); - | ^^ borrowed value does not live long enough +LL | let a = 0; + | - binding `a` declared here +LL | let cell = Cell::new(&a); + | ----------^^- + | | | + | | borrowed value does not live long enough + | argument requires that `a` is borrowed for `'static` ... -LL | / foo(cell, |cell_a, cell_x| { -LL | | cell_x.set(cell_a.get()); // forces 'a: 'x, implies 'a = 'static -> borrow error -LL | | }) - | |______- argument requires that `a` is borrowed for `'static` -LL | } - | - `a` dropped here while still borrowed +LL | } + | - `a` dropped here while still borrowed error: aborting due to 2 previous errors diff --git a/tests/ui/nll/user-annotations/adt-nullary-enums.stderr b/tests/ui/nll/user-annotations/adt-nullary-enums.stderr index bca85a90d1908..766f41790ecbf 100644 --- a/tests/ui/nll/user-annotations/adt-nullary-enums.stderr +++ b/tests/ui/nll/user-annotations/adt-nullary-enums.stderr @@ -1,16 +1,17 @@ error[E0597]: `c` does not live long enough --> $DIR/adt-nullary-enums.rs:33:41 | -LL | let c = 66; - | - binding `c` declared here -LL | / combine( -LL | | SomeEnum::SomeVariant(Cell::new(&c)), - | | ^^ borrowed value does not live long enough -LL | | SomeEnum::SomeOtherVariant::>, -LL | | ); - | |_____- argument requires that `c` is borrowed for `'static` -LL | } - | - `c` dropped here while still borrowed +LL | let c = 66; + | - binding `c` declared here +LL | combine( +LL | SomeEnum::SomeVariant(Cell::new(&c)), + | ----------^^- + | | | + | | borrowed value does not live long enough + | argument requires that `c` is borrowed for `'static` +... +LL | } + | - `c` dropped here while still borrowed error[E0597]: `c` does not live long enough --> $DIR/adt-nullary-enums.rs:41:41 diff --git a/tests/ui/traits/impl-of-supertrait-has-wrong-lifetime-parameters.stderr b/tests/ui/traits/impl-of-supertrait-has-wrong-lifetime-parameters.stderr index 1bace8ab2864b..648da9335259c 100644 --- a/tests/ui/traits/impl-of-supertrait-has-wrong-lifetime-parameters.stderr +++ b/tests/ui/traits/impl-of-supertrait-has-wrong-lifetime-parameters.stderr @@ -4,16 +4,16 @@ error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'b` d LL | impl<'a,'b> T2<'a, 'b> for S<'a, 'b> { | ^^^^^^^^^ | -note: first, the lifetime cannot outlive the lifetime `'a` as defined here... - --> $DIR/impl-of-supertrait-has-wrong-lifetime-parameters.rs:24:6 - | -LL | impl<'a,'b> T2<'a, 'b> for S<'a, 'b> { - | ^^ -note: ...but the lifetime must also be valid for the lifetime `'b` as defined here... +note: first, the lifetime cannot outlive the lifetime `'b` as defined here... --> $DIR/impl-of-supertrait-has-wrong-lifetime-parameters.rs:24:9 | LL | impl<'a,'b> T2<'a, 'b> for S<'a, 'b> { | ^^ +note: ...but the lifetime must also be valid for the lifetime `'a` as defined here... + --> $DIR/impl-of-supertrait-has-wrong-lifetime-parameters.rs:24:6 + | +LL | impl<'a,'b> T2<'a, 'b> for S<'a, 'b> { + | ^^ note: ...so that the types are compatible --> $DIR/impl-of-supertrait-has-wrong-lifetime-parameters.rs:24:28 | diff --git a/tests/ui/traits/matching-lifetimes.stderr b/tests/ui/traits/matching-lifetimes.stderr index f8119ed415d03..8a802d57f5ccc 100644 --- a/tests/ui/traits/matching-lifetimes.stderr +++ b/tests/ui/traits/matching-lifetimes.stderr @@ -6,16 +6,16 @@ LL | fn foo(x: Foo<'b,'a>) { | = note: expected signature `fn(Foo<'a, 'b>)` found signature `fn(Foo<'b, 'a>)` -note: the lifetime `'b` as defined here... - --> $DIR/matching-lifetimes.rs:13:9 - | -LL | impl<'a,'b> Tr for Foo<'a,'b> { - | ^^ -note: ...does not necessarily outlive the lifetime `'a` as defined here +note: the lifetime `'a` as defined here... --> $DIR/matching-lifetimes.rs:13:6 | LL | impl<'a,'b> Tr for Foo<'a,'b> { | ^^ +note: ...does not necessarily outlive the lifetime `'b` as defined here + --> $DIR/matching-lifetimes.rs:13:9 + | +LL | impl<'a,'b> Tr for Foo<'a,'b> { + | ^^ error[E0308]: method not compatible with trait --> $DIR/matching-lifetimes.rs:14:5 @@ -25,16 +25,16 @@ LL | fn foo(x: Foo<'b,'a>) { | = note: expected signature `fn(Foo<'a, 'b>)` found signature `fn(Foo<'b, 'a>)` -note: the lifetime `'a` as defined here... - --> $DIR/matching-lifetimes.rs:13:6 - | -LL | impl<'a,'b> Tr for Foo<'a,'b> { - | ^^ -note: ...does not necessarily outlive the lifetime `'b` as defined here +note: the lifetime `'b` as defined here... --> $DIR/matching-lifetimes.rs:13:9 | LL | impl<'a,'b> Tr for Foo<'a,'b> { | ^^ +note: ...does not necessarily outlive the lifetime `'a` as defined here + --> $DIR/matching-lifetimes.rs:13:6 + | +LL | impl<'a,'b> Tr for Foo<'a,'b> { + | ^^ error: aborting due to 2 previous errors