]> git.lizzy.rs Git - rust.git/blob - tests/ui/cstring.rs
Auto merge of #5522 - CrazyRoka:match_vec_item, r=phansch
[rust.git] / tests / ui / cstring.rs
1 #![deny(clippy::temporary_cstring_as_ptr)]
2
3 fn main() {}
4
5 fn temporary_cstring() {
6     use std::ffi::CString;
7
8     CString::new("foo").unwrap().as_ptr();
9     CString::new("foo").expect("dummy").as_ptr();
10 }
11
12 mod issue4375 {
13     use std::ffi::CString;
14     use std::os::raw::c_char;
15
16     extern "C" {
17         fn foo(data: *const c_char);
18     }
19
20     pub fn bar(v: &[u8]) {
21         let cstr = CString::new(v);
22         unsafe { foo(cstr.unwrap().as_ptr()) }
23     }
24 }