Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

string_lit_as_bytes should also detect "str".to_string().into_bytes() #6927

Closed
repi opened this issue Mar 17, 2021 · 1 comment · Fixed by #6959
Closed

string_lit_as_bytes should also detect "str".to_string().into_bytes() #6927

repi opened this issue Mar 17, 2021 · 1 comment · Fixed by #6959
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing good-first-issue These issues are a good way to get started with Clippy I-false-negative Issue: The lint should have been triggered on code, but wasn't

Comments

@repi
Copy link

repi commented Mar 17, 2021

Lint name: string_lit_as_bytes

I tried this code:

let bytes1 = "Length".as_bytes();

let bytes2 = "Length".to_string().into_bytes();

I expected to see this happen: for the second case (bytes2) to also be detected by the lint and recommend using `b"Length" instead

Instead, this happened: only the first case for bytes1 was detected.

This came from real user code we had and manually fixed, would be nice if the lint can be extended to this case as well.

Meta

  • clippy 0.0.212 (cb75ad5d 2021-02-10)
  • rustc -Vv:
     rustc 1.50.0 (cb75ad5db 2021-02-10)
     binary: rustc
     commit-hash: cb75ad5db02783e8b0222fee363c5f63f7e2cf5b
     commit-date: 2021-02-10
     host: x86_64-pc-windows-msvc
     release: 1.50.0
    
@repi repi added C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't labels Mar 17, 2021
@giraffate giraffate added the good-first-issue These issues are a good way to get started with Clippy label Mar 17, 2021
@ebobrow
Copy link
Contributor

ebobrow commented Mar 23, 2021

I'd like to give this a try.

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing good-first-issue These issues are a good way to get started with Clippy I-false-negative Issue: The lint should have been triggered on code, but wasn't
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants