Description
Hello all, I've found a false positive for a lint:
warning: calling `as_bytes()` on a string literal
--> xxx\src\xxx.rs:81:35
|
81 | let current_version = env!("CARGO_PKG_VERSION").as_bytes();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using a byte string literal instead: `benv!("CARGO_PKG_VERSION")`
|
= note: `#[warn(clippy::string_lit_as_bytes)]` on by default
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#string_lit_as_bytes
warning: 1 warning emitted
clippy 0.0.212 (7ebd87a7a 2020-05-08)
A binary literal can't be used with the env! macro and the suggestion to fix it obviously doesn't work. In this case I would say that calling as_bytes()
is the proper thing to do.
I've tested whether or not this is a general macro problem, but that doesn't seem to be the case:
macro_rules! test {
($x: expr) => {
$x
}
}
warning: calling `as_bytes()` on a string literal
--> rtls-uwb\src\messages\join_request.rs:88:35
|
88 | let current_version = test!("CARGO_PKG_VERSION").as_bytes();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using a byte string literal instead: `b"CARGO_PKG_VERSION"`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#string_lit_as_bytes
warning: 3 warnings emitted