]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/strlen_on_c_strings.rs
Rollup merge of #87453 - ibraheemdev:i-68697, r=wesleywiser
[rust.git] / src / tools / clippy / tests / ui / strlen_on_c_strings.rs
1 #![warn(clippy::strlen_on_c_strings)]
2 #![allow(dead_code)]
3 #![feature(rustc_private)]
4 extern crate libc;
5
6 use std::ffi::{CStr, CString};
7
8 fn main() {
9     // CString
10     let cstring = CString::new("foo").expect("CString::new failed");
11     let len = unsafe { libc::strlen(cstring.as_ptr()) };
12
13     // CStr
14     let cstr = CStr::from_bytes_with_nul(b"foo\0").expect("CStr::from_bytes_with_nul failed");
15     let len = unsafe { libc::strlen(cstr.as_ptr()) };
16 }