use rustc::middle::const_val::ConstVal;
use rustc::ty;
use rustc_const_eval::ConstContext;
-use rustc_const_math::{ConstUsize,ConstIsize,ConstInt};
+use rustc_const_math::{ConstUsize, ConstIsize, ConstInt};
use rustc::hir;
use syntax::ast::RangeLimits;
use utils::{self, higher};
// Array with known size can be checked statically
let ty = cx.tables.expr_ty(array);
if let ty::TyArray(_, size) = ty.sty {
- let size = ConstInt::Usize(ConstUsize::new(size as u64, cx.sess().target.uint_type).expect("array size is invalid"));
+ let size = ConstInt::Usize(ConstUsize::new(size as u64, cx.sess().target.uint_type)
+ .expect("array size is invalid"));
let constcx = ConstContext::with_tables(cx.tcx, cx.tables);
// Index is a constant uint
Some(Some(ConstVal::Integral(x))) => {
if limits == RangeLimits::Closed {
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")
+ 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
}
use rustc_const_eval::lookup_const_by_id;
use rustc_const_math::ConstInt;
use rustc::hir::*;
-use rustc::ty::{TyCtxt, self};
+use rustc::ty::{self, TyCtxt};
use std::cmp::Ordering::{self, Equal};
use std::cmp::PartialOrd;
use std::hash::{Hash, Hasher};
match (&ty.sty, hint) {
(&ty::TyInt(ity), _) |
(_, Signed(ity)) => {
- Constant::Int(ConstInt::new_signed_truncating(n as i128,
- ity, tcx.sess.target.int_type))
- }
+ Constant::Int(ConstInt::new_signed_truncating(n as i128, ity, tcx.sess.target.int_type))
+ },
(&ty::TyUint(uty), _) |
(_, Unsigned(uty)) => {
- Constant::Int(ConstInt::new_unsigned_truncating(n as u128,
- uty, tcx.sess.target.uint_type))
- }
- _ => bug!()
+ Constant::Int(ConstInt::new_unsigned_truncating(n as u128, uty, tcx.sess.target.uint_type))
+ },
+ _ => bug!(),
}
- }
+ },
LitKind::Float(ref is, ty) => Constant::Float(is.to_string(), ty.into()),
LitKind::FloatUnsuffixed(ref is) => Constant::Float(is.to_string(), FloatWidth::Any),
LitKind::Bool(b) => Constant::Bool(b),
if let Some((const_expr, tables)) = lookup_const_by_id(self.tcx, def_id, substs) {
let mut cx = ConstEvalLateContext {
tcx: self.tcx,
- tables,
+ tables: tables,
needed_resolution: false,
};
let ret = cx.expr(const_expr);
};
let els_str = els.map_or(String::new(), |els| format!(" else {}", expr_block(cx, els, None, "..")));
span_lint_and_then(cx,
- lint,
- expr.span,
- "you seem to be trying to use match for destructuring a single pattern. \
- Consider using `if let`",
- |db| {
+ lint,
+ expr.span,
+ "you seem to be trying to use match for destructuring a single pattern. Consider using `if \
+ let`",
+ |db| {
db.span_suggestion(expr.span,
- "try this",
- format!("if let {} = {} {}{}",
+ "try this",
+ format!("if let {} = {} {}{}",
snippet(cx, arms[0].pats[0].span, ".."),
snippet(cx, ex.span, ".."),
expr_block(cx, &arms[0].body, None, ".."),