Clippy False Positive error message "cannot call non-const formatting macro in constants"

The code from the answer is flagged as

error[E0015]: cannot call non-const formatting macro in constants
  --> src/lib.rs:42:27
   |
42 |                 Err(_) => unreachable!("Buffer is always ascii")
   |                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Is it because it is nightly? How can I get rid of it?

If you use a panic directly instead of unreachable!, Clippy doesn't mind:

match core::str::from_utf8(buffer) {
    Ok(x) => x,
    Err(_) => panic!("internal error: entered unreachable code: Buffer is always ascii"),
}

Playground.

1 Like