Skip to content

Commit a4a0894

Browse files
committed
fix example and mention that the compiler checks c"" literals
1 parent 06cfa5e commit a4a0894

File tree

1 file changed

+4
-3
lines changed
  • clippy_lints/src/methods

1 file changed

+4
-3
lines changed

clippy_lints/src/methods/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3758,18 +3758,19 @@ declare_clippy_lint! {
37583758
/// Checks for calls to `CString::new` and `CStr::from_bytes_with_nul` with byte string literals as arguments.
37593759
///
37603760
/// ### Why is this bad?
3761-
/// This can be written more concisely using `c"str"` literals.
3761+
/// This can be written more concisely using `c"str"` literals and is also less error-prone,
3762+
/// because the compiler checks for interior nul bytes.
37623763
///
37633764
/// ### Example
37643765
/// ```no_run
37653766
/// # use std::ffi::CStr;
3766-
/// # fn needs_cstr(_: &str) {}
3767+
/// # fn needs_cstr(_: &CStr) {}
37673768
/// needs_cstr(CStr::from_bytes_with_nul(b":)").unwrap());
37683769
/// ```
37693770
/// Use instead:
37703771
/// ```no_run
37713772
/// # use std::ffi::CStr;
3772-
/// # fn needs_cstr(_: &str) {}
3773+
/// # fn needs_cstr(_: &CStr) {}
37733774
/// needs_cstr(c":)");
37743775
/// ```
37753776
#[clippy::version = "1.76.0"]

0 commit comments

Comments
 (0)