diff --git a/src/libcore/num/f32.rs b/src/libcore/num/f32.rs index ebc30dc8b61fb..5068375368466 100644 --- a/src/libcore/num/f32.rs +++ b/src/libcore/num/f32.rs @@ -10,8 +10,7 @@ //! Operations and constants for 32-bits floats (`f32` type) -// FIXME: MIN_VALUE and MAX_VALUE literals are parsed as -inf and inf #14353 -#![allow(overflowing_literals)] +#![cfg_attr(stage0, allow(overflowing_literals))] #![stable(feature = "rust1", since = "1.0.0")] diff --git a/src/libcore/num/f64.rs b/src/libcore/num/f64.rs index 1a1fe4d86e0d0..4ff80a2f05d41 100644 --- a/src/libcore/num/f64.rs +++ b/src/libcore/num/f64.rs @@ -10,9 +10,6 @@ //! Operations and constants for 64-bits floats (`f64` type) -// FIXME: MIN_VALUE and MAX_VALUE literals are parsed as -inf and inf #14353 -#![allow(overflowing_literals)] - #![stable(feature = "rust1", since = "1.0.0")] use intrinsics; diff --git a/src/librustc_lint/types.rs b/src/librustc_lint/types.rs index ac3977bd216e7..1237132f61542 100644 --- a/src/librustc_lint/types.rs +++ b/src/librustc_lint/types.rs @@ -173,18 +173,17 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits { } } ty::TyFloat(t) => { - let (min, max) = float_ty_range(t); - let lit_val: f64 = match lit.node { + let is_infinite = match lit.node { ast::LitKind::Float(v, _) | ast::LitKind::FloatUnsuffixed(v) => { - match v.as_str().parse() { - Ok(f) => f, - Err(_) => return, + match t { + ast::FloatTy::F32 => v.as_str().parse().map(f32::is_infinite), + ast::FloatTy::F64 => v.as_str().parse().map(f64::is_infinite), } } _ => bug!(), }; - if lit_val < min || lit_val > max { + if is_infinite == Ok(true) { cx.span_lint(OVERFLOWING_LITERALS, e.span, &format!("literal out of range for {:?}", t)); @@ -242,13 +241,6 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits { } } - fn float_ty_range(float_ty: ast::FloatTy) -> (f64, f64) { - match float_ty { - ast::FloatTy::F32 => (f32::MIN as f64, f32::MAX as f64), - ast::FloatTy::F64 => (f64::MIN, f64::MAX), - } - } - fn int_ty_bits(int_ty: ast::IntTy, target_int_ty: ast::IntTy) -> u64 { match int_ty { ast::IntTy::Is => int_ty_bits(target_int_ty, target_int_ty), diff --git a/src/test/compile-fail/lint-type-overflow2.rs b/src/test/compile-fail/lint-type-overflow2.rs index a2971f23a79e1..d399fda328625 100644 --- a/src/test/compile-fail/lint-type-overflow2.rs +++ b/src/test/compile-fail/lint-type-overflow2.rs @@ -17,8 +17,8 @@ fn main() { let x2: i8 = --128; //~ error: literal out of range for i8 //~^ error: attempt to negate with overflow - let x = -3.40282348e+38_f32; //~ error: literal out of range for f32 - let x = 3.40282348e+38_f32; //~ error: literal out of range for f32 + let x = -3.40282357e+38_f32; //~ error: literal out of range for f32 + let x = 3.40282357e+38_f32; //~ error: literal out of range for f32 let x = -1.7976931348623159e+308_f64; //~ error: literal out of range for f64 let x = 1.7976931348623159e+308_f64; //~ error: literal out of range for f64 } diff --git a/src/test/run-pass/big-literals.rs b/src/test/run-pass/big-literals.rs index 19c0e7baaa0a1..56e0039f66de3 100644 --- a/src/test/run-pass/big-literals.rs +++ b/src/test/run-pass/big-literals.rs @@ -8,9 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - -#![feature(core)] - // Catch mistakes in the overflowing literals lint. #![deny(overflowing_literals)] @@ -21,4 +18,9 @@ pub fn main() { assert_eq!(18446744073709551615, (!0 as u64)); assert_eq!((-2147483648i32).wrapping_sub(1), 2147483647); + + assert_eq!(-3.40282356e+38_f32, ::std::f32::MIN); + assert_eq!(3.40282356e+38_f32, ::std::f32::MAX); + assert_eq!(-1.7976931348623158e+308_f64, ::std::f64::MIN); + assert_eq!(1.7976931348623158e+308_f64, ::std::f64::MAX); }