Skip to content

Commit b713571

Browse files
committed
---
yaml --- r: 225257 b: refs/heads/stable c: c654a07 h: refs/heads/master i: 225255: 23fb74b v: v3
1 parent 5da609b commit b713571

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ refs/heads/tmp: e5d90d98402475b6e154ce216f9efcb80da1a747
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f
3030
refs/tags/homu-tmp: 1fe32ca12c51afcd761d9962f51a74ff0d07a591
3131
refs/tags/1.0.0-beta: 8cbb92b53468ee2b0c2d3eeb8567005953d40828
32-
refs/heads/stable: 0ec3183df8d0cdccc735fa6572d664b43dbb5e31
32+
refs/heads/stable: c654a07d29c77b5a023cb9d36dfc61811349f64e
3333
refs/tags/1.0.0: 55bd4f8ff2b323f317ae89e254ce87162d52a375
3434
refs/tags/1.1.0: bc3c16f09287e5545c1d3f76b7abd54f2eca868b

branches/stable/src/librustc_lint/builtin.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,12 @@ impl LintPass for TypeLimits {
203203
} else {
204204
t
205205
};
206-
let (min, max) = int_ty_range(int_type);
206+
let (_, max) = int_ty_range(int_type);
207207
let negative = self.negated_expr_id == e.id;
208208

209-
if (negative && min != i64::MIN && v > -min as u64) ||
209+
// Detect literal value out of range [min, max] inclusive
210+
// avoiding use of -min to prevent overflow/panic
211+
if (negative && v > max as u64 + 1) ||
210212
(!negative && v > max as u64) {
211213
cx.span_lint(OVERFLOWING_LITERALS, e.span,
212214
&*format!("literal out of range for {:?}", t));

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ fn main() {
5252
let x = 9223372036854775808_i64; //~ error: literal out of range for i64
5353
let x = -9223372036854775808_i64; // should be OK
5454
let x = 18446744073709551615_i64; //~ error: literal out of range for i64
55+
let x: i64 = -9223372036854775809; //~ error: literal out of range for i64
56+
let x = -9223372036854775809_i64; //~ error: literal out of range for i64
5557

5658
let x = -3.40282348e+38_f32; //~ error: literal out of range for f32
5759
let x = 3.40282348e+38_f32; //~ error: literal out of range for f32

0 commit comments

Comments
 (0)