-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check inferred integer literals for overflows, closes #4220
- Loading branch information
Showing
7 changed files
with
126 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
// | ||
|
||
#[deny(type_overflow)]; | ||
|
||
fn test(x: i8) { | ||
println!("x {}", x); | ||
} | ||
|
||
#[allow(unused_variable)] | ||
fn main() { | ||
let x1: u8 = 255; // should be OK | ||
let x1: u8 = 256; //~ error: literal out of range for its type | ||
|
||
let x1 = 255_u8; // should be OK | ||
let x1 = 256_u8; //~ error: literal out of range for its type | ||
|
||
let x2: i8 = -128; // should be OK | ||
let x1: i8 = 128; //~ error: literal out of range for its type | ||
let x2: i8 = --128; //~ error: literal out of range for its type | ||
|
||
let x3: i8 = -129; //~ error: literal out of range for its type | ||
let x3: i8 = -(129); //~ error: literal out of range for its type | ||
let x3: i8 = -{129}; //~ error: literal out of range for its type | ||
|
||
test(1000); //~ error: literal out of range for its type | ||
|
||
let x = 128_i8; //~ error: literal out of range for its type | ||
let x = 127_i8; | ||
let x = -128_i8; | ||
let x = -(128_i8); | ||
let x = -129_i8; //~ error: literal out of range for its type | ||
|
||
let x: i32 = 2147483647; // should be OK | ||
let x = 2147483647_i32; // should be OK | ||
let x: i32 = 2147483648; //~ error: literal out of range for its type | ||
let x = 2147483648_i32; //~ error: literal out of range for its type | ||
let x: i32 = -2147483648; // should be OK | ||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20627c7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
saw approval from alexcrichton
at fhahn@20627c7
20627c7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merging fhahn/rust/check-inferred-ints = 20627c7 into auto
20627c7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fhahn/rust/check-inferred-ints = 20627c7 merged ok, testing candidate = ade310c
20627c7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all tests pass:
success: http://buildbot.rust-lang.org/builders/auto-mac-32-opt/builds/2470
success: http://buildbot.rust-lang.org/builders/auto-mac-32-nopt-c/builds/316
success: http://buildbot.rust-lang.org/builders/auto-mac-32-nopt-t/builds/316
success: http://buildbot.rust-lang.org/builders/auto-mac-64-opt/builds/2474
success: http://buildbot.rust-lang.org/builders/auto-mac-64-nopt-c/builds/1580
success: http://buildbot.rust-lang.org/builders/auto-mac-64-nopt-t/builds/1579
success: http://buildbot.rust-lang.org/builders/auto-linux-32-opt/builds/2488
success: http://buildbot.rust-lang.org/builders/auto-linux-32-nopt-c/builds/1580
success: http://buildbot.rust-lang.org/builders/auto-linux-32-nopt-t/builds/1580
success: http://buildbot.rust-lang.org/builders/auto-linux-64-opt/builds/2489
success: http://buildbot.rust-lang.org/builders/auto-linux-64-nopt-c/builds/1580
success: http://buildbot.rust-lang.org/builders/auto-linux-64-nopt-t/builds/1580
success: http://buildbot.rust-lang.org/builders/auto-linux-64-x-android/builds/1656
success: http://buildbot.rust-lang.org/builders/auto-win-32-opt/builds/2474
success: http://buildbot.rust-lang.org/builders/auto-win-32-nopt-c/builds/1578
success: http://buildbot.rust-lang.org/builders/auto-win-32-nopt-t/builds/1580
success: http://buildbot.rust-lang.org/builders/auto-bsd-64-opt/builds/2252
20627c7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fast-forwarding master to auto = ade310c