Skip to content

Commit 6e25e10

Browse files
committed
fix typos, adjust suggestion, add description
1 parent a4a0894 commit 6e25e10

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

clippy_lints/src/methods/manual_c_str_literals.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ fn check_from_ptr(cx: &LateContext<'_>, expr: &Expr<'_>, arg: &Expr<'_>) {
4444
MANUAL_C_STR_LITERALS,
4545
expr.span,
4646
"calling `CStr::from_ptr` with a byte string literal",
47-
"use a c-str literal",
47+
r#"use a `c""` literal"#,
4848
rewrite_as_cstr(cx, lit.span),
4949
Applicability::MachineApplicable,
5050
);
@@ -71,7 +71,7 @@ fn check_from_bytes(cx: &LateContext<'_>, expr: &Expr<'_>, arg: &Expr<'_>, metho
7171
MANUAL_C_STR_LITERALS,
7272
span,
7373
"calling `CStr::new` with a byte string literal",
74-
"use a c-str literal",
74+
r#"use a `c""` literal"#,
7575
rewrite_as_cstr(cx, arg.span),
7676
applicability,
7777
);

clippy_lints/src/methods/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3755,7 +3755,7 @@ declare_clippy_lint! {
37553755

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

37823782
pub struct Methods {

tests/ui/manual_c_str_literals.stderr

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error: calling `CStr::new` with a byte string literal
22
--> $DIR/manual_c_str_literals.rs:32:5
33
|
44
LL | CStr::from_bytes_with_nul(b"foo\0");
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use a c-str literal: `c"foo"`
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use a `c""` literal: `c"foo"`
66
|
77
= note: `-D clippy::manual-c-str-literals` implied by `-D warnings`
88
= help: to override `-D warnings` add `#[allow(clippy::manual_c_str_literals)]`
@@ -11,37 +11,37 @@ error: calling `CStr::new` with a byte string literal
1111
--> $DIR/manual_c_str_literals.rs:36:5
1212
|
1313
LL | CStr::from_bytes_with_nul(b"foo\0");
14-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use a c-str literal: `c"foo"`
14+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use a `c""` literal: `c"foo"`
1515

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

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

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

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

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

4646
error: aborting due to 7 previous errors
4747

0 commit comments

Comments
 (0)