]> git.lizzy.rs Git - rust.git/blob - tests/ui/strlen_on_c_strings.rs
Auto merge of #88214 - notriddle:notriddle/for-loop-span-drop-temps-mut, r=nagisa
[rust.git] / 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 }