Skip to content

Commit 26270c7

Browse files
committed
Fix ice
1 parent 268b15f commit 26270c7

File tree

2 files changed

+19
-31
lines changed

2 files changed

+19
-31
lines changed

clippy_lints/src/consts.rs

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,6 @@ pub enum Constant {
5353
Tuple(Vec<Constant>),
5454
}
5555

56-
impl Constant {
57-
/// Convert to `u64` if possible.
58-
///
59-
/// # panics
60-
///
61-
/// If the constant could not be converted to `u64` losslessly.
62-
fn as_u64(&self) -> u64 {
63-
if let Constant::Int(val) = *self {
64-
val.to_u64().expect("negative constant can't be casted to `u64`")
65-
} else {
66-
panic!("Could not convert a `{:?}` to `u64`", self);
67-
}
68-
}
69-
}
70-
7156
impl PartialEq for Constant {
7257
fn eq(&self, other: &Constant) -> bool {
7358
match (self, other) {
@@ -266,11 +251,12 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
266251
ExprLit(ref lit) => Some(lit_to_constant(&lit.node, self.tcx, self.tables.expr_ty(e))),
267252
ExprArray(ref vec) => self.multi(vec).map(Constant::Vec),
268253
ExprTup(ref tup) => self.multi(tup).map(Constant::Tuple),
269-
ExprRepeat(ref value, number_id) => {
270-
let val = &self.tcx.hir.body(number_id).value;
271-
self.binop_apply(value,
272-
val,
273-
|v, n| Some(Constant::Repeat(Box::new(v), n.as_u64() as usize)))
254+
ExprRepeat(ref value, _) => {
255+
let n = match self.tables.expr_ty(e).sty {
256+
ty::TyArray(_, n) => n,
257+
_ => span_bug!(e.span, "typeck error"),
258+
};
259+
self.expr(value).map(|v| Constant::Repeat(Box::new(v), n))
274260
},
275261
ExprUnary(op, ref operand) => {
276262
self.expr(operand).and_then(|o| match op {
@@ -375,15 +361,4 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
375361
_ => None,
376362
}
377363
}
378-
379-
380-
fn binop_apply<F>(&mut self, left: &Expr, right: &Expr, op: F) -> Option<Constant>
381-
where F: Fn(Constant, Constant) -> Option<Constant>
382-
{
383-
if let (Some(lc), Some(rc)) = (self.expr(left), self.expr(right)) {
384-
op(lc, rc)
385-
} else {
386-
None
387-
}
388-
}
389364
}

tests/run-pass/ice-1588.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#![feature(plugin)]
2+
#![plugin(clippy)]
3+
#![allow(clippy)]
4+
5+
fn main() {
6+
match 1 {
7+
1 => {}
8+
2 => {
9+
[0; 1];
10+
}
11+
_ => {}
12+
}
13+
}

0 commit comments

Comments
 (0)