|
|
|
|
|
by Jtsummers
395 days ago
|
|
Not that you should ever write this in any language, but as an illustration: fn main() {
let x: i32 = if true {1} else {"3"};
println!("{}", x);
}
This will not compile even though if it were allowed to execute it would, correctly, assign an integer to x. Python will happily interpret its equivalent: x = 1 if True else "3"
print(x)
Even giving the if-expression an explicit `true` constant for the condition, Rust won't accept that as a valid program even though we can prove that the result of the expression is always 1. |
|