Skip to content

Commit

Permalink
Auto merge of rust-lang#9627 - Jarcho:ice-9625, r=xFrednet
Browse files Browse the repository at this point in the history
Use the correct type when comparing nested constants.

fixes rust-lang#9625

changelog: `manual_range_contains`: fix ICE when the values are behind a reference
  • Loading branch information
bors committed Oct 12, 2022
2 parents b8a9a50 + 0cc7492 commit 45dd9f3
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
44 changes: 38 additions & 6 deletions clippy_utils/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,17 +136,49 @@ impl Constant {
(&Self::F64(l), &Self::F64(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::Tuple(ref l), &Self::Tuple(ref r)) | (&Self::Vec(ref l), &Self::Vec(ref r)) => 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::Tuple(ref l), &Self::Tuple(ref r)) if l.len() == r.len() => match *cmp_type.kind() {
ty::Tuple(tys) if tys.len() == l.len() => l
.iter()
.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)) => {
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)),
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?
_ => None,
}
Expand Down
4 changes: 4 additions & 0 deletions tests/ui/crashes/ice-9625.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fn main() {
let x = &1;
let _ = &1 < x && x < &10;
}

0 comments on commit 45dd9f3

Please sign in to comment.