Skip to content

Commit 36a1c33

Browse files
committed
---
yaml --- r: 211332 b: refs/heads/tmp c: c654a07 h: refs/heads/master v: v3
1 parent 757dc50 commit 36a1c33

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
@@ -32,7 +32,7 @@ refs/heads/building: 126db549b038c84269a1e4fe46f051b2c15d6970
3232
refs/heads/beta: 2d00dc3b85aaf81caa3a4e5764c5e185a4dd0a7c
3333
refs/heads/windistfix: 7608dbad651f02e837ed05eef3d74a6662a6e928
3434
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
35-
refs/heads/tmp: 0ec3183df8d0cdccc735fa6572d664b43dbb5e31
35+
refs/heads/tmp: c654a07d29c77b5a023cb9d36dfc61811349f64e
3636
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f
3737
refs/tags/homu-tmp: 704c2ee730d2e948d11a2edd77e3f35de8329a6e
3838
refs/heads/gate: 97c84447b65164731087ea82685580cc81424412

branches/tmp/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/tmp/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)