Use the correct type when comparing nested constants.
This commit is contained in:
parent
cf72565a12
commit
0cc749296f
@ -136,17 +136,49 @@ impl Constant {
|
|||||||
(&Self::F64(l), &Self::F64(r)) => l.partial_cmp(&r),
|
(&Self::F64(l), &Self::F64(r)) => l.partial_cmp(&r),
|
||||||
(&Self::F32(l), &Self::F32(r)) => l.partial_cmp(&r),
|
(&Self::F32(l), &Self::F32(r)) => l.partial_cmp(&r),
|
||||||
(&Self::Bool(ref l), &Self::Bool(ref r)) => Some(l.cmp(r)),
|
(&Self::Bool(ref l), &Self::Bool(ref r)) => Some(l.cmp(r)),
|
||||||
(&Self::Tuple(ref l), &Self::Tuple(ref r)) | (&Self::Vec(ref l), &Self::Vec(ref r)) => iter::zip(l, r)
|
(&Self::Tuple(ref l), &Self::Tuple(ref r)) if l.len() == r.len() => match *cmp_type.kind() {
|
||||||
.map(|(li, ri)| Self::partial_cmp(tcx, cmp_type, li, ri))
|
ty::Tuple(tys) if tys.len() == l.len() => l
|
||||||
.find(|r| r.map_or(true, |o| o != Ordering::Equal))
|
.iter()
|
||||||
.unwrap_or_else(|| Some(l.len().cmp(&r.len()))),
|
.zip(r)
|
||||||
|
.zip(tys)
|
||||||
|
.map(|((li, ri), cmp_type)| Self::partial_cmp(tcx, cmp_type, li, ri))
|
||||||
|
.find(|r| r.map_or(true, |o| o != Ordering::Equal))
|
||||||
|
.unwrap_or_else(|| Some(l.len().cmp(&r.len()))),
|
||||||
|
_ => None,
|
||||||
|
},
|
||||||
|
(&Self::Vec(ref l), &Self::Vec(ref r)) => {
|
||||||
|
let cmp_type = match *cmp_type.kind() {
|
||||||
|
ty::Array(ty, _) | ty::Slice(ty) => ty,
|
||||||
|
_ => return None,
|
||||||
|
};
|
||||||
|
iter::zip(l, r)
|
||||||
|
.map(|(li, ri)| Self::partial_cmp(tcx, cmp_type, li, ri))
|
||||||
|
.find(|r| r.map_or(true, |o| o != Ordering::Equal))
|
||||||
|
.unwrap_or_else(|| Some(l.len().cmp(&r.len())))
|
||||||
|
},
|
||||||
(&Self::Repeat(ref lv, ref ls), &Self::Repeat(ref rv, ref rs)) => {
|
(&Self::Repeat(ref lv, ref ls), &Self::Repeat(ref rv, ref rs)) => {
|
||||||
match Self::partial_cmp(tcx, cmp_type, lv, rv) {
|
match Self::partial_cmp(
|
||||||
|
tcx,
|
||||||
|
match *cmp_type.kind() {
|
||||||
|
ty::Array(ty, _) => ty,
|
||||||
|
_ => return None,
|
||||||
|
},
|
||||||
|
lv,
|
||||||
|
rv,
|
||||||
|
) {
|
||||||
Some(Equal) => Some(ls.cmp(rs)),
|
Some(Equal) => Some(ls.cmp(rs)),
|
||||||
x => x,
|
x => x,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
(&Self::Ref(ref lb), &Self::Ref(ref rb)) => Self::partial_cmp(tcx, cmp_type, lb, rb),
|
(&Self::Ref(ref lb), &Self::Ref(ref rb)) => Self::partial_cmp(
|
||||||
|
tcx,
|
||||||
|
match *cmp_type.kind() {
|
||||||
|
ty::Ref(_, ty, _) => ty,
|
||||||
|
_ => return None,
|
||||||
|
},
|
||||||
|
lb,
|
||||||
|
rb,
|
||||||
|
),
|
||||||
// TODO: are there any useful inter-type orderings?
|
// TODO: are there any useful inter-type orderings?
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
|
4
tests/ui/crashes/ice-9625.rs
Normal file
4
tests/ui/crashes/ice-9625.rs
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
fn main() {
|
||||||
|
let x = &1;
|
||||||
|
let _ = &1 < x && x < &10;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user