auto merge of #14874 : pcwalton/rust/enum-to-float-casts-part-deux, r=alexcrichton
Closes #14794. If you're casting from an enum to a float, cast through an integer first. [breaking-change] r? @alexcrichton
This commit is contained in:
commit
dbd29ea96e
7 changed files with 32 additions and 18 deletions
|
|
@ -8,7 +8,7 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// Tests that enum-to-float-casts do *signed* integer-to-float conversion.
|
||||
// Tests that enum-to-float casts are disallowed.
|
||||
|
||||
enum E {
|
||||
L0 = -1,
|
||||
|
|
@ -20,13 +20,13 @@ enum F {
|
|||
H1 = 0xFFFFFFFFFFFFFFFF
|
||||
}
|
||||
|
||||
static C0: f32 = L0 as f32;
|
||||
static C1: f32 = H1 as f32;
|
||||
static C0: f32 = L0 as f32; //~ ERROR illegal cast
|
||||
static C1: f32 = H1 as f32; //~ ERROR illegal cast
|
||||
|
||||
pub fn main() {
|
||||
let a = L0 as f32;
|
||||
let a = L0 as f32; //~ ERROR illegal cast
|
||||
let b = C0;
|
||||
let c = H1 as f32;
|
||||
let c = H1 as f32; //~ ERROR illegal cast
|
||||
let d = C1;
|
||||
assert_eq!(a, -1.0f32);
|
||||
assert_eq!(b, -1.0f32);
|
||||
|
|
@ -14,18 +14,10 @@ enum B { B1=0, B2=2 }
|
|||
pub fn main () {
|
||||
static c1: int = A2 as int;
|
||||
static c2: int = B2 as int;
|
||||
static c3: f64 = A2 as f64;
|
||||
static c4: f64 = B2 as f64;
|
||||
let a1 = A2 as int;
|
||||
let a2 = B2 as int;
|
||||
let a3 = A2 as f64;
|
||||
let a4 = B2 as f64;
|
||||
assert_eq!(c1, 1);
|
||||
assert_eq!(c2, 2);
|
||||
assert_eq!(c3, 1.0);
|
||||
assert_eq!(c4, 2.0);
|
||||
assert_eq!(a1, 1);
|
||||
assert_eq!(a2, 2);
|
||||
assert_eq!(a3, 1.0);
|
||||
assert_eq!(a4, 2.0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,5 +21,4 @@ pub fn main() {
|
|||
|
||||
fn test_color(color: color, val: int, _name: String) {
|
||||
assert!(color as int == val);
|
||||
assert!(color as f64 == val as f64);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,7 +40,6 @@ pub fn main() {
|
|||
fn test_color(color: color, val: int, name: String) {
|
||||
//assert!(unsafe::transmute(color) == val);
|
||||
assert_eq!(color as int, val);
|
||||
assert_eq!(color as f64, val as f64);
|
||||
assert!(get_color_alt(color) == name);
|
||||
assert!(get_color_if(color) == name);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue