E0094Arithmetic on
Error
Arithmetic on char
ErrorThe binary +, -, *, / and % and the compound assignments +=, -=, *=, /= and %= do not take a char, on either side. The sign -c is not arithmetic on a char: it is E0032, as c is not an i64. A char is compared with ==, !=, <, <=, > and >=, by code point, and converted with i64(c).
Why
A char is a Unicode scalar value, not a number. Adding to it can land on a code point that is no char, in the gap D800 to DFFF or past 10FFFF. The program says where a char becomes a number and where it becomes a char again. char(n) gives a char?, which is None when n is not a scalar value, so the program also says what to use then: a default with ??, or a branch with if let.
Broken
fn main() {
let c = 'a'
print(c + 1)
}
What sisu says
error[E0094]: arithmetic does not apply to `char` --> E0094.sisu:3:13 | 3 | print(c + 1) | ^ | = help: convert through `i64`, then give a default: `char(i64(c) + 1) ?? c` sisu: 1 error sisu: for more on a code, run `sisu explain <code>`: E0094
Fixed
fn main() {
let c = 'a'
print(char(i64(c) + 1) ?? c)
}
Sisu