use std::cmp;
use std::collections::HashMap;
-use std::i16;
-use std::i32;
-use std::i64;
-use std::i8;
-use std::u16;
-use std::u32;
-use std::u64;
-use std::u8;
+use std::{i8, i16, i32, i64, u8, u16, u32, u64, f32, f64};
use std::gc::Gc;
use syntax::abi;
use syntax::ast_map;
"literal out of range for its type");
}
},
-
+ ty::ty_float(t) => {
+ let (min, max) = float_ty_range(t);
+ let lit_val: f64 = match lit.node {
+ ast::LitFloat(ref v, _) |
+ ast::LitFloatUnsuffixed(ref v) => match from_str(v.get()) {
+ Some(f) => f,
+ None => return
+ },
+ _ => fail!()
+ };
+ if lit_val < min || lit_val > max {
+ cx.span_lint(TYPE_OVERFLOW, e.span,
+ "literal out of range for its type");
+ }
+ },
_ => ()
};
},
}
}
+ fn float_ty_range(float_ty: ast::FloatTy) -> (f64, f64) {
+ match float_ty {
+ ast::TyF32 => (f32::MIN_VALUE as f64, f32::MAX_VALUE as f64),
+ ast::TyF64 => (f64::MIN_VALUE, f64::MAX_VALUE)
+ }
+ }
+
fn check_limits(tcx: &ty::ctxt, binop: ast::BinOp,
l: &ast::Expr, r: &ast::Expr) -> bool {
let (lit, expr, swap) = match (&l.node, &r.node) {
let x = -2147483648_i32; // should be OK
let x: i32 = -2147483649; //~ error: literal out of range for its type
let x = -2147483649_i32; //~ error: literal out of range for its type
+
+ let x = -3.40282348e+38_f32; //~ error: literal out of range for its type
+ let x = 3.40282348e+38_f32; //~ error: literal out of range for its type
+ let x = -1.7976931348623159e+308_f64; //~ error: literal out of range for its type
+ let x = 1.7976931348623159e+308_f64; //~ error: literal out of range for its type
}