Skip to content

Commit

Permalink
Auto merge of #13263 - y21:warn_manual_c_str_literals, r=Centri3
Browse files Browse the repository at this point in the history
move `manual_c_str_literals` to complexity

IMO the suggestion to use `c""` literals over a hardcoded `\0` byte string literal has some fairly strong upsides (no need to manually null-terminate it and the compiler checks for intermediary null bytes) that this should just be enabled by default.

It's also written slightly conservatively to only emit a warning when we can be reasonably confident that the lint is *actually* applicable (that is, lint on e.g. `b"foo\0".as_ptr()` but not `b"foo\0"`. The latter looks like a c-string but its type is `&[u8; _]`, and if it's used in a context where a byte slice is needed then you have no nice way to convert to it from a `c"foo"` literal of type `&CStr`).

changelog: move [`manual_c_str_literals`] to complexity (now warn-by-default)
  • Loading branch information
bors committed Sep 3, 2024
2 parents e8ba5d1 + a5e3a3f commit f2ef26d
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion clippy_lints/src/methods/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4036,7 +4036,7 @@ declare_clippy_lint! {
/// ```
#[clippy::version = "1.78.0"]
pub MANUAL_C_STR_LITERALS,
pedantic,
complexity,
r#"creating a `CStr` through functions when `c""` literals can be used"#
}

Expand Down

0 comments on commit f2ef26d

Please sign in to comment.