Skip to content

Handle the new clippy::manual_c_str_literals lint #2994

Closed
@nyurik

Description

@nyurik

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions