Skip to content

Commit 4e7e71b

Browse files
committed
Fix ICE #4579
1 parent 75d951e commit 4e7e71b

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

clippy_lints/src/consts.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ impl Constant {
152152
}
153153

154154
/// Parses a `LitKind` to a `Constant`.
155-
pub fn lit_to_constant(lit: &LitKind, ty: Ty<'_>) -> Constant {
155+
pub fn lit_to_constant(lit: &LitKind, ty: Option<Ty<'_>>) -> Constant {
156156
use syntax::ast::*;
157157

158158
match *lit {
@@ -161,7 +161,9 @@ pub fn lit_to_constant(lit: &LitKind, ty: Ty<'_>) -> Constant {
161161
LitKind::ByteStr(ref s) => Constant::Binary(Lrc::clone(s)),
162162
LitKind::Char(c) => Constant::Char(c),
163163
LitKind::Int(n, _) => Constant::Int(n),
164-
LitKind::Float(ref is, _) | LitKind::FloatUnsuffixed(ref is) => match ty.sty {
164+
LitKind::Float(ref is, FloatTy::F32) => Constant::F32(is.as_str().parse().unwrap()),
165+
LitKind::Float(ref is, FloatTy::F64) => Constant::F64(is.as_str().parse().unwrap()),
166+
LitKind::FloatUnsuffixed(ref is) => match ty.expect("type of float is known").sty {
165167
ty::Float(FloatTy::F32) => Constant::F32(is.as_str().parse().unwrap()),
166168
ty::Float(FloatTy::F64) => Constant::F64(is.as_str().parse().unwrap()),
167169
_ => bug!(),
@@ -225,7 +227,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
225227
match e.node {
226228
ExprKind::Path(ref qpath) => self.fetch_path(qpath, e.hir_id),
227229
ExprKind::Block(ref block, _) => self.block(block),
228-
ExprKind::Lit(ref lit) => Some(lit_to_constant(&lit.node, self.tables.expr_ty(e))),
230+
ExprKind::Lit(ref lit) => Some(lit_to_constant(&lit.node, self.tables.expr_ty_opt(e))),
229231
ExprKind::Array(ref vec) => self.multi(vec).map(Constant::Vec),
230232
ExprKind::Tup(ref tup) => self.multi(tup).map(Constant::Tuple),
231233
ExprKind::Repeat(ref value, _) => {

clippy_lints/src/neg_multiply.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NegMultiply {
4949
fn check_mul(cx: &LateContext<'_, '_>, span: Span, lit: &Expr, exp: &Expr) {
5050
if_chain! {
5151
if let ExprKind::Lit(ref l) = lit.node;
52-
if let Constant::Int(val) = consts::lit_to_constant(&l.node, cx.tables.expr_ty(lit));
52+
if let Constant::Int(val) = consts::lit_to_constant(&l.node, cx.tables.expr_ty_opt(lit));
5353
if val == 1;
5454
if cx.tables.expr_ty(exp).is_integral();
5555
then {

0 commit comments

Comments
 (0)