]> git.lizzy.rs Git - rust.git/blob - tests/ui/strlen_on_c_strings.rs
Fix `strlen_on_c_strings` when not used with a full path
[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 libc::strlen;
7 use std::ffi::{CStr, CString};
8
9 fn main() {
10     // CString
11     let cstring = CString::new("foo").expect("CString::new failed");
12     let len = unsafe { libc::strlen(cstring.as_ptr()) };
13
14     // CStr
15     let cstr = CStr::from_bytes_with_nul(b"foo\0").expect("CStr::from_bytes_with_nul failed");
16     let len = unsafe { libc::strlen(cstr.as_ptr()) };
17
18     let len = unsafe { strlen(cstr.as_ptr()) };
19 }