Skip to content

Commit 12b540a

Browse files
committed
Revert "avoid PartialOrd on ScalarInt"
This reverts commit a1049bd.
1 parent a1049bd commit 12b540a

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

compiler/rustc_middle/src/thir.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_hir::{BindingAnnotation, ByRef, HirId, MatchSource, RangeEnd};
1616
use rustc_index::newtype_index;
1717
use rustc_index::IndexVec;
1818
use rustc_middle::middle::region;
19-
use rustc_middle::mir::interpret::AllocId;
19+
use rustc_middle::mir::interpret::{AllocId, Scalar};
2020
use rustc_middle::mir::{self, BinOp, BorrowKind, FakeReadCause, UnOp};
2121
use rustc_middle::ty::adjustment::PointerCoercion;
2222
use rustc_middle::ty::layout::IntegerExt;
@@ -1012,14 +1012,15 @@ impl<'tcx> PatRangeBoundary<'tcx> {
10121012
// raw data comparisons are appropriate. E.g. `unicode-normalization` has
10131013
// many ranges such as '\u{037A}'..='\u{037F}', and chars can be compared
10141014
// in this way.
1015-
(Finite(a), Finite(b)) if matches!(ty.kind(), ty::Uint(_) | ty::Char) => {
1016-
if let (Some(a), Some(b)) = (a.try_to_scalar_int(), b.try_to_scalar_int()) {
1017-
let sz = ty.primitive_size(tcx);
1018-
let a = a.assert_uint(sz);
1019-
let b = b.assert_uint(sz);
1020-
return Some(a.cmp(&b));
1021-
}
1015+
(Finite(mir::Const::Ty(a)), Finite(mir::Const::Ty(b)))
1016+
if matches!(ty.kind(), ty::Uint(_) | ty::Char) =>
1017+
{
1018+
return Some(a.to_valtree().cmp(&b.to_valtree()));
10221019
}
1020+
(
1021+
Finite(mir::Const::Val(mir::ConstValue::Scalar(Scalar::Int(a)), _)),
1022+
Finite(mir::Const::Val(mir::ConstValue::Scalar(Scalar::Int(b)), _)),
1023+
) if matches!(ty.kind(), ty::Uint(_) | ty::Char) => return Some(a.cmp(&b)),
10231024
_ => {}
10241025
}
10251026

compiler/rustc_middle/src/ty/consts/int.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ impl IntoDiagArg for ConstInt {
126126
///
127127
/// This is a packed struct in order to allow this type to be optimally embedded in enums
128128
/// (like Scalar).
129-
#[derive(Clone, Copy, Eq, PartialEq, Hash)]
129+
#[derive(Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)]
130130
#[repr(packed)]
131131
pub struct ScalarInt {
132132
/// The first `size` bytes of `data` are the value.

compiler/rustc_middle/src/ty/consts/valtree.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::mir::interpret::Scalar;
33
use crate::ty::{self, Ty, TyCtxt};
44
use rustc_macros::{HashStable, TyDecodable, TyEncodable};
55

6-
#[derive(Copy, Clone, Debug, Hash, TyEncodable, TyDecodable, Eq, PartialEq)]
6+
#[derive(Copy, Clone, Debug, Hash, TyEncodable, TyDecodable, Eq, PartialEq, Ord, PartialOrd)]
77
#[derive(HashStable)]
88
/// This datastructure is used to represent the value of constants used in the type system.
99
///

0 commit comments

Comments
 (0)