Fix ty::TyKind usage
This commit is contained in:
parent
20a07f6d80
commit
36ee92780d
2 changed files with 3 additions and 8 deletions
|
@ -119,17 +119,12 @@ impl Hash for Constant {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Constant {
|
impl Constant {
|
||||||
pub fn partial_cmp(
|
pub fn partial_cmp(tcx: TyCtxt<'_, '_, '_>, cmp_type: ty::Ty<'_>, left: &Self, right: &Self) -> Option<Ordering> {
|
||||||
tcx: TyCtxt<'_, '_, '_>,
|
|
||||||
cmp_type: &ty::TyKind<'_>,
|
|
||||||
left: &Self,
|
|
||||||
right: &Self,
|
|
||||||
) -> Option<Ordering> {
|
|
||||||
match (left, right) {
|
match (left, right) {
|
||||||
(&Constant::Str(ref ls), &Constant::Str(ref rs)) => Some(ls.cmp(rs)),
|
(&Constant::Str(ref ls), &Constant::Str(ref rs)) => Some(ls.cmp(rs)),
|
||||||
(&Constant::Char(ref l), &Constant::Char(ref r)) => Some(l.cmp(r)),
|
(&Constant::Char(ref l), &Constant::Char(ref r)) => Some(l.cmp(r)),
|
||||||
(&Constant::Int(l), &Constant::Int(r)) => {
|
(&Constant::Int(l), &Constant::Int(r)) => {
|
||||||
if let ty::Int(int_ty) = *cmp_type {
|
if let ty::Int(int_ty) = cmp_type.sty {
|
||||||
Some(sext(tcx, l, int_ty).cmp(&sext(tcx, r, int_ty)))
|
Some(sext(tcx, l, int_ty).cmp(&sext(tcx, r, int_ty)))
|
||||||
} else {
|
} else {
|
||||||
Some(l.cmp(&r))
|
Some(l.cmp(&r))
|
||||||
|
|
|
@ -51,7 +51,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MinMaxPass {
|
||||||
}
|
}
|
||||||
match (
|
match (
|
||||||
outer_max,
|
outer_max,
|
||||||
Constant::partial_cmp(cx.tcx, &cx.tables.expr_ty(ie).sty, &outer_c, &inner_c),
|
Constant::partial_cmp(cx.tcx, cx.tables.expr_ty(ie), &outer_c, &inner_c),
|
||||||
) {
|
) {
|
||||||
(_, None) | (MinMax::Max, Some(Ordering::Less)) | (MinMax::Min, Some(Ordering::Greater)) => (),
|
(_, None) | (MinMax::Max, Some(Ordering::Less)) | (MinMax::Min, Some(Ordering::Greater)) => (),
|
||||||
_ => {
|
_ => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue