Skip to content

Commit 4b211a3

Browse files
committed
Run uibless
1 parent 85b381d commit 4b211a3

File tree

2 files changed

+45
-21
lines changed

2 files changed

+45
-21
lines changed

tests/ui/strlen_on_c_strings.fixed

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,41 +7,41 @@ use std::ffi::{CStr, CString};
77
fn main() {
88
// CString
99
let cstring = CString::new("foo").expect("CString::new failed");
10-
let _ = cstring.to_bytes().len();
10+
let _ = cstring.count_bytes();
1111
//~^ ERROR: using `libc::strlen` on a `CString` value
1212

1313
// CStr
1414
let cstr = CStr::from_bytes_with_nul(b"foo\0").expect("CStr::from_bytes_with_nul failed");
15-
let _ = cstr.to_bytes().len();
15+
let _ = cstr.count_bytes();
1616
//~^ ERROR: using `libc::strlen` on a `CStr` value
1717

18-
let _ = cstr.to_bytes().len();
18+
let _ = cstr.count_bytes();
1919
//~^ ERROR: using `libc::strlen` on a `CStr` value
2020

2121
let pcstr: *const &CStr = &cstr;
22-
let _ = unsafe { (*pcstr).to_bytes().len() };
22+
let _ = unsafe { (*pcstr).count_bytes() };
2323
//~^ ERROR: using `libc::strlen` on a `CStr` value
2424

2525
unsafe fn unsafe_identity<T>(x: T) -> T {
2626
x
2727
}
28-
let _ = unsafe { unsafe_identity(cstr).to_bytes().len() };
28+
let _ = unsafe { unsafe_identity(cstr).count_bytes() };
2929
//~^ ERROR: using `libc::strlen` on a `CStr` value
30-
let _ = unsafe { unsafe_identity(cstr) }.to_bytes().len();
30+
let _ = unsafe { unsafe_identity(cstr) }.count_bytes();
3131
//~^ ERROR: using `libc::strlen` on a `CStr` value
3232

3333
let f: unsafe fn(_) -> _ = unsafe_identity;
34-
let _ = unsafe { f(cstr).to_bytes().len() };
34+
let _ = unsafe { f(cstr).count_bytes() };
3535
//~^ ERROR: using `libc::strlen` on a `CStr` value
3636
}
3737

3838
// make sure we lint types that _adjust_ to `CStr`
3939
fn adjusted(box_cstring: Box<CString>, box_cstr: Box<CStr>, arc_cstring: std::sync::Arc<CStr>) {
40-
let _ = box_cstring.to_bytes().len();
40+
let _ = box_cstring.count_bytes();
4141
//~^ ERROR: using `libc::strlen` on a type that dereferences to `CStr`
42-
let _ = box_cstr.to_bytes().len();
42+
let _ = box_cstr.count_bytes();
4343
//~^ ERROR: using `libc::strlen` on a type that dereferences to `CStr`
44-
let _ = arc_cstring.to_bytes().len();
44+
let _ = arc_cstring.count_bytes();
4545
//~^ ERROR: using `libc::strlen` on a type that dereferences to `CStr`
4646
}
4747

tests/ui/strlen_on_c_strings.stderr

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error: using `libc::strlen` on a `CString` value
22
--> tests/ui/strlen_on_c_strings.rs:10:13
33
|
44
LL | let _ = unsafe { libc::strlen(cstring.as_ptr()) };
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `cstring.to_bytes().len()`
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `cstring.count_bytes()`
66
|
77
= note: `-D clippy::strlen-on-c-strings` implied by `-D warnings`
88
= help: to override `-D warnings` add `#[allow(clippy::strlen_on_c_strings)]`
@@ -11,55 +11,79 @@ error: using `libc::strlen` on a `CStr` value
1111
--> tests/ui/strlen_on_c_strings.rs:15:13
1212
|
1313
LL | let _ = unsafe { libc::strlen(cstr.as_ptr()) };
14-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `cstr.to_bytes().len()`
14+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `cstr.count_bytes()`
1515

1616
error: using `libc::strlen` on a `CStr` value
1717
--> tests/ui/strlen_on_c_strings.rs:18:13
1818
|
1919
LL | let _ = unsafe { strlen(cstr.as_ptr()) };
20-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `cstr.to_bytes().len()`
20+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `cstr.count_bytes()`
2121

2222
error: using `libc::strlen` on a `CStr` value
2323
--> tests/ui/strlen_on_c_strings.rs:22:22
2424
|
2525
LL | let _ = unsafe { strlen((*pcstr).as_ptr()) };
26-
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `(*pcstr).to_bytes().len()`
26+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `(*pcstr).count_bytes()`
2727

2828
error: using `libc::strlen` on a `CStr` value
2929
--> tests/ui/strlen_on_c_strings.rs:28:22
3030
|
3131
LL | let _ = unsafe { strlen(unsafe_identity(cstr).as_ptr()) };
32-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `unsafe_identity(cstr).to_bytes().len()`
32+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `unsafe_identity(cstr).count_bytes()`
3333

3434
error: using `libc::strlen` on a `CStr` value
3535
--> tests/ui/strlen_on_c_strings.rs:30:13
3636
|
3737
LL | let _ = unsafe { strlen(unsafe { unsafe_identity(cstr) }.as_ptr()) };
38-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `unsafe { unsafe_identity(cstr) }.to_bytes().len()`
38+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `unsafe { unsafe_identity(cstr) }.count_bytes()`
3939

4040
error: using `libc::strlen` on a `CStr` value
4141
--> tests/ui/strlen_on_c_strings.rs:34:22
4242
|
4343
LL | let _ = unsafe { strlen(f(cstr).as_ptr()) };
44-
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `f(cstr).to_bytes().len()`
44+
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `f(cstr).count_bytes()`
4545

4646
error: using `libc::strlen` on a type that dereferences to `CStr`
4747
--> tests/ui/strlen_on_c_strings.rs:40:13
4848
|
4949
LL | let _ = unsafe { libc::strlen(box_cstring.as_ptr()) };
50-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `box_cstring.to_bytes().len()`
50+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `box_cstring.count_bytes()`
5151

5252
error: using `libc::strlen` on a type that dereferences to `CStr`
5353
--> tests/ui/strlen_on_c_strings.rs:42:13
5454
|
5555
LL | let _ = unsafe { libc::strlen(box_cstr.as_ptr()) };
56-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `box_cstr.to_bytes().len()`
56+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `box_cstr.count_bytes()`
5757

5858
error: using `libc::strlen` on a type that dereferences to `CStr`
5959
--> tests/ui/strlen_on_c_strings.rs:44:13
6060
|
6161
LL | let _ = unsafe { libc::strlen(arc_cstring.as_ptr()) };
62-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `arc_cstring.to_bytes().len()`
62+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `arc_cstring.count_bytes()`
63+
64+
error: using `libc::strlen` on a `CStr` value
65+
--> tests/ui/strlen_on_c_strings.rs:51:13
66+
|
67+
LL | let _ = unsafe { libc::strlen(cstr.as_ptr()) };
68+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `cstr.to_bytes().len()`
69+
70+
error: using `libc::strlen` on a `CString` value
71+
--> tests/ui/strlen_on_c_strings.rs:55:13
72+
|
73+
LL | let _ = unsafe { libc::strlen(cstring.as_ptr()) };
74+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `cstring.as_bytes().len()`
75+
76+
error: using `libc::strlen` on a `CStr` value
77+
--> tests/ui/strlen_on_c_strings.rs:62:13
78+
|
79+
LL | let _ = unsafe { libc::strlen(cstr.as_ptr()) };
80+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `cstr.count_bytes()`
81+
82+
error: using `libc::strlen` on a `CString` value
83+
--> tests/ui/strlen_on_c_strings.rs:66:13
84+
|
85+
LL | let _ = unsafe { libc::strlen(cstring.as_ptr()) };
86+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `cstring.count_bytes()`
6387

64-
error: aborting due to 10 previous errors
88+
error: aborting due to 14 previous errors
6589

0 commit comments

Comments
 (0)