-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
rust-lang/rust
#72637Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingE-needs-testCall for participation: writing testsCall for participation: writing testsI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedIssue: The suggestions provided by this Lint cause an ICE/error when appliedT-macrosType: Issues with macros and macro expansionType: Issues with macros and macro expansiongood first issueThese issues are a good way to get started with ClippyThese issues are a good way to get started with Clippy
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
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingE-needs-testCall for participation: writing testsCall for participation: writing testsI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedIssue: The suggestions provided by this Lint cause an ICE/error when appliedT-macrosType: Issues with macros and macro expansionType: Issues with macros and macro expansiongood first issueThese issues are a good way to get started with ClippyThese issues are a good way to get started with Clippy