Skip to content

Commit

Permalink
fix typos, adjust suggestion, add description
Browse files Browse the repository at this point in the history
  • Loading branch information
y21 committed Dec 3, 2023
1 parent a4a0894 commit 6e25e10
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions clippy_lints/src/methods/manual_c_str_literals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn check_from_ptr(cx: &LateContext<'_>, expr: &Expr<'_>, arg: &Expr<'_>) {
MANUAL_C_STR_LITERALS,
expr.span,
"calling `CStr::from_ptr` with a byte string literal",
"use a c-str literal",
r#"use a `c""` literal"#,
rewrite_as_cstr(cx, lit.span),
Applicability::MachineApplicable,
);
Expand All @@ -71,7 +71,7 @@ fn check_from_bytes(cx: &LateContext<'_>, expr: &Expr<'_>, arg: &Expr<'_>, metho
MANUAL_C_STR_LITERALS,
span,
"calling `CStr::new` with a byte string literal",
"use a c-str literal",
r#"use a `c""` literal"#,
rewrite_as_cstr(cx, arg.span),
applicability,
);
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/methods/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3755,7 +3755,7 @@ declare_clippy_lint! {

declare_clippy_lint! {
/// ### What it does
/// Checks for calls to `CString::new` and `CStr::from_bytes_with_nul` with byte string literals as arguments.
/// Checks for calls to `CString::from_ptr` and `CStr::from_bytes_with_nul` with byte string literals as arguments.
///
/// ### Why is this bad?
/// This can be written more concisely using `c"str"` literals and is also less error-prone,
Expand All @@ -3776,7 +3776,7 @@ declare_clippy_lint! {
#[clippy::version = "1.76.0"]
pub MANUAL_C_STR_LITERALS,
pedantic,
"default lint description"
r#"creating a `CStr` through functions when `c""` literals can be used"#
}

pub struct Methods {
Expand Down
14 changes: 7 additions & 7 deletions tests/ui/manual_c_str_literals.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error: calling `CStr::new` with a byte string literal
--> $DIR/manual_c_str_literals.rs:32:5
|
LL | CStr::from_bytes_with_nul(b"foo\0");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use a c-str literal: `c"foo"`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use a `c""` literal: `c"foo"`
|
= note: `-D clippy::manual-c-str-literals` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::manual_c_str_literals)]`
Expand All @@ -11,37 +11,37 @@ error: calling `CStr::new` with a byte string literal
--> $DIR/manual_c_str_literals.rs:36:5
|
LL | CStr::from_bytes_with_nul(b"foo\0");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use a c-str literal: `c"foo"`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use a `c""` literal: `c"foo"`

error: calling `CStr::new` with a byte string literal
--> $DIR/manual_c_str_literals.rs:37:5
|
LL | CStr::from_bytes_with_nul(b"foo\x00");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use a c-str literal: `c"foo"`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use a `c""` literal: `c"foo"`

error: calling `CStr::new` with a byte string literal
--> $DIR/manual_c_str_literals.rs:38:5
|
LL | CStr::from_bytes_with_nul(b"foo\0").unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use a c-str literal: `c"foo"`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use a `c""` literal: `c"foo"`

error: calling `CStr::new` with a byte string literal
--> $DIR/manual_c_str_literals.rs:39:5
|
LL | CStr::from_bytes_with_nul(b"foo\\0sdsd\0").unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use a c-str literal: `c"foo\\0sdsd"`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use a `c""` literal: `c"foo\\0sdsd"`

error: calling `CStr::from_ptr` with a byte string literal
--> $DIR/manual_c_str_literals.rs:44:14
|
LL | unsafe { CStr::from_ptr(b"foo\0".as_ptr().cast()) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use a c-str literal: `c"foo"`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use a `c""` literal: `c"foo"`

error: calling `CStr::from_ptr` with a byte string literal
--> $DIR/manual_c_str_literals.rs:45:14
|
LL | unsafe { CStr::from_ptr(b"foo\0".as_ptr() as *const _) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use a c-str literal: `c"foo"`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use a `c""` literal: `c"foo"`

error: aborting due to 7 previous errors

0 comments on commit 6e25e10

Please sign in to comment.