Skip to content

Commit 40cc726

Browse files
committed
update for bool/char being checked at binops
1 parent 42bce6c commit 40cc726

File tree

5 files changed

+19
-5
lines changed

5 files changed

+19
-5
lines changed

tests/compile-fail/invalid_bool.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
//ignore-test FIXME (do some basic validation of invariants for all values in flight)
2+
//This does currently not get caught becuase it compiles to SwitchInt, which
3+
//has no knowledge about data invariants.
24

35
fn main() {
46
let b = unsafe { std::mem::transmute::<u8, bool>(2) };
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fn main() {
2+
let b = unsafe { std::mem::transmute::<u8, bool>(2) };
3+
let _x = b == true; //~ ERROR invalid boolean value read
4+
}

tests/compile-fail/match_char.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
// ignore-test FIXME: we are not checking these things on match any more?
2+
//This does currently not get caught becuase it compiles to SwitchInt, which
3+
//has no knowledge about data invariants.
24

35
fn main() {
46
assert!(std::char::from_u32(-1_i32 as u32).is_none());
5-
match unsafe { std::mem::transmute::<i32, char>(-1) } { //~ ERROR constant evaluation error
7+
let _ = match unsafe { std::mem::transmute::<i32, char>(-1) } { //~ ERROR constant evaluation error
68
//~^ NOTE tried to interpret an invalid 32-bit value as a char: 4294967295
7-
'a' => {},
8-
'b' => {},
9-
_ => {},
10-
}
9+
'a' => {true},
10+
'b' => {false},
11+
_ => {true},
12+
};
1113
}

tests/compile-fail/match_char2.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
fn main() {
2+
assert!(std::char::from_u32(-1_i32 as u32).is_none());
3+
let c = unsafe { std::mem::transmute::<i32, char>(-1) };
4+
let _x = c == 'x'; //~ ERROR tried to interpret an invalid 32-bit value as a char
5+
}

tests/run-pass/bools.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ fn main() {
2525
assert_eq!(if_false(), 0);
2626
assert_eq!(if_true(), 1);
2727
assert_eq!(match_bool(), 1);
28+
assert_eq!(true == true, true);
2829
}

0 commit comments

Comments
 (0)