Skip to content

Commit 735b740

Browse files
committed
---
yaml --- r: 123509 b: refs/heads/auto c: a672456 h: refs/heads/master i: 123507: 6293999 v: v3
1 parent d9a2d48 commit 735b740

File tree

8 files changed

+55
-11
lines changed

8 files changed

+55
-11
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1313
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1414
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1515
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
16-
refs/heads/auto: bfa853f8ed45d1908c98ec350f52c7a6790661da
16+
refs/heads/auto: a672456c40d28f051ecbdb2caf5bf6733371d494
1717
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1818
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1919
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/mk/dist.mk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,6 @@ distcheck-tar-bins: dist-tar-bins
259259
$(Q)cd tmp/distcheck && tar -xzf ../../dist/$(PKG_NAME)-$(CFG_BUILD).tar.gz
260260
$(Q)mkdir -p tmp/distcheck/tarbininstall
261261
$(Q)sh tmp/distcheck/$(PKG_NAME)-$(CFG_BUILD)/install.sh --prefix=tmp/distcheck/tarbininstall
262-
$(Q)tmp/distcheck/tarbininstall/bin/rustc --version
263262
$(Q)sh tmp/distcheck/$(PKG_NAME)-$(CFG_BUILD)/install.sh --prefix=tmp/distcheck/tarbininstall --uninstall
264263
$(Q)rm -Rf tmp/distcheck/$(PKG_NAME)-$(CFG_BUILD)
265264
$(Q)rm -Rf tmp/distcheck/tarbininstall

branches/auto/src/libcore/num/f32.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
//! Operations and constants for 32-bits floats (`f32` type)
1212
1313
#![doc(primitive = "f32")]
14+
// FIXME: MIN_VALUE and MAX_VALUE literals are parsed as -inf and inf #14353
15+
#![allow(type_overflow)]
1416

1517
use intrinsics;
1618
use mem;

branches/auto/src/libcore/num/f64.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
//! Operations and constants for 64-bits floats (`f64` type)
1212
1313
#![doc(primitive = "f64")]
14+
// FIXME: MIN_VALUE and MAX_VALUE literals are parsed as -inf and inf #14353
15+
#![allow(type_overflow)]
1416

1517
use intrinsics;
1618
use mem;

branches/auto/src/librustc/lint/builtin.rs

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,7 @@ use lint::{Context, LintPass, LintArray};
3737

3838
use std::cmp;
3939
use std::collections::HashMap;
40-
use std::i16;
41-
use std::i32;
42-
use std::i64;
43-
use std::i8;
44-
use std::u16;
45-
use std::u32;
46-
use std::u64;
47-
use std::u8;
40+
use std::{i8, i16, i32, i64, u8, u16, u32, u64, f32, f64};
4841
use std::gc::Gc;
4942
use syntax::abi;
5043
use syntax::ast_map;
@@ -214,7 +207,21 @@ impl LintPass for TypeLimits {
214207
"literal out of range for its type");
215208
}
216209
},
217-
210+
ty::ty_float(t) => {
211+
let (min, max) = float_ty_range(t);
212+
let lit_val: f64 = match lit.node {
213+
ast::LitFloat(ref v, _) |
214+
ast::LitFloatUnsuffixed(ref v) => match from_str(v.get()) {
215+
Some(f) => f,
216+
None => return
217+
},
218+
_ => fail!()
219+
};
220+
if lit_val < min || lit_val > max {
221+
cx.span_lint(TYPE_OVERFLOW, e.span,
222+
"literal out of range for its type");
223+
}
224+
},
218225
_ => ()
219226
};
220227
},
@@ -265,6 +272,13 @@ impl LintPass for TypeLimits {
265272
}
266273
}
267274

275+
fn float_ty_range(float_ty: ast::FloatTy) -> (f64, f64) {
276+
match float_ty {
277+
ast::TyF32 => (f32::MIN_VALUE as f64, f32::MAX_VALUE as f64),
278+
ast::TyF64 => (f64::MIN_VALUE, f64::MAX_VALUE)
279+
}
280+
}
281+
268282
fn check_limits(tcx: &ty::ctxt, binop: ast::BinOp,
269283
l: &ast::Expr, r: &ast::Expr) -> bool {
270284
let (lit, expr, swap) = match (&l.node, &r.node) {

branches/auto/src/librustc/middle/typeck/check/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,6 +1219,13 @@ fn check_cast(fcx: &FnCtxt,
12191219
actual,
12201220
fcx.infcx().ty_to_string(t_1))
12211221
}, t_e, None);
1222+
} else if ty::type_is_unsafe_ptr(t_e) && t_1_is_float {
1223+
fcx.type_error_message(span, |actual| {
1224+
format!("cannot cast from pointer to float directly: `{}` as `{}`; cast through an \
1225+
integer first",
1226+
actual,
1227+
fcx.infcx().ty_to_string(t_1))
1228+
}, t_e, None);
12221229
}
12231230

12241231
fcx.write_ty(id, t_1);

branches/auto/src/test/compile-fail/lint-type-overflow.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,9 @@ fn main() {
4747
let x = -2147483648_i32; // should be OK
4848
let x: i32 = -2147483649; //~ error: literal out of range for its type
4949
let x = -2147483649_i32; //~ error: literal out of range for its type
50+
51+
let x = -3.40282348e+38_f32; //~ error: literal out of range for its type
52+
let x = 3.40282348e+38_f32; //~ error: literal out of range for its type
53+
let x = -1.7976931348623159e+308_f64; //~ error: literal out of range for its type
54+
let x = 1.7976931348623159e+308_f64; //~ error: literal out of range for its type
5055
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
let x : i16 = 22;
13+
((&x) as *const i16) as f32;
14+
//~^ ERROR: cannot cast from pointer to float directly: `*const i16` as `f32`
15+
}

0 commit comments

Comments
 (0)