Handle the new clippy::manual_c_str_literals
lint · Issue #2994 · rust-lang/rust-bindgen (original) (raw)
Navigation Menu
- Explore
- Pricing
Provide feedback
Saved searches
Use saved searches to filter your results more quickly
Appearance settings
Description
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 callingfrom_bytes_with_nul_unchecked