Sisu
E0111

Precision on a value that is not an f64

ErrorSafe fix

Built from the repository at commit a8614dc.

A precision in a format spec, {x:.2}, sets the number of decimals of an f64. Any other value has no decimals, so a precision on it is an error. The error points at the spec, from its :.

Why

An i64, a u8, a bool, a char and a string have no decimals to round. Rust takes a precision on a string to cut it short, and Python rejects it on an integer; Sisu gives it the one meaning. For an i64, the fix converts the value with f64(...), which never fails; beyond 2^53 it rounds to the nearest f64. Any other type gets no fix: remove the precision, or convert the value yourself.

Broken

fn main() {
    let n = 7
    print("{n:.2}")
}

What sisu says

error[E0111]: precision needs an `f64`
 --> E0111.sisu:3:14
  |
3 |     print("{n:.2}")
  |              ^^^ the value is `i64`
  |
help: convert it with `f64(...)`
  |
3 |     print("{f64(n):.2}")
  |             ++++ +

sisu: 1 error
sisu: for more on a code, run `sisu explain <code>`: E0111

Fixed

fn main() {
    let n = 7
    print("{f64(n):.2}")
}

Related

  • E0032: a mismatched type, which offers f64(...) for an i64 too.