Skip to content

Commit 83f90aa

Browse files
committed
Auto merge of #4590 - flip1995:ice_4579, r=Manishearth
Fix ICE #4579 Fixes #4579 Fixes #4584 r? @phansch changelog: Fix ICE caused by Clippys const-utils
2 parents 648e5b9 + eb1fc7b commit 83f90aa

File tree

4 files changed

+23
-8
lines changed

4 files changed

+23
-8
lines changed

.travis.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ matrix:
6262
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
6363
- env: INTEGRATION=rust-lang/rustfmt
6464
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
65-
- env: INTEGRATION=hyperium/hyper
66-
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
65+
# - env: INTEGRATION=hyperium/hyper
66+
# if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
6767
- env: INTEGRATION=bluss/rust-itertools
6868
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
6969
- env: INTEGRATION=serde-rs/serde
@@ -72,8 +72,8 @@ matrix:
7272
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
7373
- env: INTEGRATION=rust-random/rand
7474
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
75-
- env: INTEGRATION=rust-lang-nursery/futures-rs
76-
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
75+
# - env: INTEGRATION=rust-lang-nursery/futures-rs
76+
# if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
7777
- env: INTEGRATION=Marwes/combine
7878
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
7979
- env: INTEGRATION=rust-lang-nursery/failure

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.kind {
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").kind {
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.kind {
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
@@ -44,7 +44,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NegMultiply {
4444
fn check_mul(cx: &LateContext<'_, '_>, span: Span, lit: &Expr, exp: &Expr) {
4545
if_chain! {
4646
if let ExprKind::Lit(ref l) = lit.kind;
47-
if let Constant::Int(1) = consts::lit_to_constant(&l.node, cx.tables.expr_ty(lit));
47+
if let Constant::Int(1) = consts::lit_to_constant(&l.node, cx.tables.expr_ty_opt(lit));
4848
if cx.tables.expr_ty(exp).is_integral();
4949
then {
5050
span_lint(cx, NEG_MULTIPLY, span, "Negation by multiplying with -1");

tests/ui/ice-4579.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#![allow(clippy::single_match)]
2+
3+
use std::ptr;
4+
5+
fn main() {
6+
match Some(0_usize) {
7+
Some(_) => {
8+
let s = "012345";
9+
unsafe { ptr::read(s.as_ptr().offset(1) as *const [u8; 5]) };
10+
},
11+
_ => (),
12+
};
13+
}

0 commit comments

Comments
 (0)