[Pre-RFC] Implicit number type widening

Comparing/assign with two variables with different types are always may be bug. Because of at first you have: a = b; or a == b and "a" and "b" have the same types. After that you do some refactoring and you get different types, but in fact you want the same types, but you forget change how "b" calculated.

At now Rust works perfectly, like in tech spec for C for safe systems (which require reduce integer promotion, compare and assign different types and so on things).

But if you allow widening even for obvious case:

let mut a: u16 = x;
let mut b: u8 = y;
a = b;

that may prevent compiler to catch bugs that developer missed after refactoring.

But you can find such things like usage of "as" in some cases, "unsafe" in some other cases. While with automatic widening there is no even clue what is wrong here during code reading.

1 Like