]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/strlen_on_c_strings.fixed
Rollup merge of #88794 - sunfishcode:sunfishcode/try-clone, r=joshtriplett
[rust.git] / src / tools / clippy / tests / ui / strlen_on_c_strings.fixed
1 // run-rustfix
2
3 #![warn(clippy::strlen_on_c_strings)]
4 #![allow(dead_code)]
5 #![feature(rustc_private)]
6 extern crate libc;
7
8 #[allow(unused)]
9 use libc::strlen;
10 use std::ffi::{CStr, CString};
11
12 fn main() {
13     // CString
14     let cstring = CString::new("foo").expect("CString::new failed");
15     let _ = cstring.as_bytes().len();
16
17     // CStr
18     let cstr = CStr::from_bytes_with_nul(b"foo\0").expect("CStr::from_bytes_with_nul failed");
19     let _ = cstr.to_bytes().len();
20
21     let _ = cstr.to_bytes().len();
22
23     let pcstr: *const &CStr = &cstr;
24     let _ = unsafe { (*pcstr).to_bytes().len() };
25
26     unsafe fn unsafe_identity<T>(x: T) -> T {
27         x
28     }
29     let _ = unsafe { unsafe_identity(cstr).to_bytes().len() };
30     let _ = unsafe { unsafe_identity(cstr) }.to_bytes().len();
31
32     let f: unsafe fn(_) -> _ = unsafe_identity;
33     let _ = unsafe { f(cstr).to_bytes().len() };
34 }