From 6f0fd15da9b65a738f20f1fdad6dcc728bcf6c11 Mon Sep 17 00:00:00 2001 From: Enrico Schmitz Date: Wed, 1 Mar 2017 16:17:30 +0100 Subject: [PATCH] Handle all types in to_const_range --- clippy_lints/src/array_indexing.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/array_indexing.rs b/clippy_lints/src/array_indexing.rs index 068fd782cf6..1cd57e632ca 100644 --- a/clippy_lints/src/array_indexing.rs +++ b/clippy_lints/src/array_indexing.rs @@ -2,7 +2,7 @@ use rustc::lint::*; use rustc::middle::const_val::ConstVal; use rustc::ty; use rustc_const_eval::ConstContext; -use rustc_const_math::{ConstUsize,ConstInt}; +use rustc_const_math::{ConstUsize,ConstIsize,ConstInt}; use rustc::hir; use syntax::ast::RangeLimits; use utils::{self, higher}; @@ -122,7 +122,24 @@ fn to_const_range( let end = match *end { Some(Some(ConstVal::Integral(x))) => { if limits == RangeLimits::Closed { - (x + ConstInt::U8(1)).expect("such a big array is not realistic") + match x { + ConstInt::U8(_) => (x + ConstInt::U8(1)), + ConstInt::U16(_) => (x + ConstInt::U16(1)), + ConstInt::U32(_) => (x + ConstInt::U32(1)), + ConstInt::U64(_) => (x + ConstInt::U64(1)), + ConstInt::U128(_) => (x + ConstInt::U128(1)), + ConstInt::Usize(ConstUsize::Us16(_)) => (x + ConstInt::Usize(ConstUsize::Us16(1))), + ConstInt::Usize(ConstUsize::Us32(_)) => (x + ConstInt::Usize(ConstUsize::Us32(1))), + ConstInt::Usize(ConstUsize::Us64(_)) => (x + ConstInt::Usize(ConstUsize::Us64(1))), + ConstInt::I8(_) => (x + ConstInt::I8(1)), + ConstInt::I16(_) => (x + ConstInt::I16(1)), + ConstInt::I32(_) => (x + ConstInt::I32(1)), + ConstInt::I64(_) => (x + ConstInt::I64(1)), + ConstInt::I128(_) => (x + ConstInt::I128(1)), + ConstInt::Isize(ConstIsize::Is16(_)) => (x + ConstInt::Isize(ConstIsize::Is16(1))), + ConstInt::Isize(ConstIsize::Is32(_)) => (x + ConstInt::Isize(ConstIsize::Is32(1))), + ConstInt::Isize(ConstIsize::Is64(_)) => (x + ConstInt::Isize(ConstIsize::Is64(1))), + }.expect("such a big array is not realistic") } else { x }