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

Handle the new clippy::manual_c_str_literals lint #2994

Closed
nyurik opened this issue Nov 28, 2024 · 0 comments · Fixed by #2996
Closed

Handle the new clippy::manual_c_str_literals lint #2994

nyurik opened this issue Nov 28, 2024 · 0 comments · Fixed by #2996

Comments

@nyurik
Copy link
Contributor

nyurik commented Nov 28, 2024

Clippy 1.83 introduced manual_c_str_literals on this type of generated code:

#[allow(unsafe_code)]
pub const VSL_CLASS: &::std::ffi::CStr =
    unsafe { ::std::ffi::CStr::from_bytes_with_nul_unchecked(b"Log\0") };
warning: calling `CStr::new` with a byte string literal
   --> .../out/bindings.rs:708:14
    |
708 |     unsafe { ::std::ffi::CStr::from_bytes_with_nul_unchecked(b"Log\0") };
    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use a `c""` literal: `c"Log"`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_c_str_literals
    = note: `#[warn(clippy::manual_c_str_literals)]` on by default

Possible solutions

  • introduce a new generate_cstr_literal(bool) flag
  • change generate_cstr(bool) to take an enum instead, e.g. Off, CStrObjects, CStrLiterals
  • add #[allow(clippy::manual_c_str_literals)] to each instance of calling from_bytes_with_nul_unchecked
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant