mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-23 21:23:56 +00:00
move cstring tests
This commit is contained in:
parent
5eeadcfc43
commit
6d94167014
4 changed files with 30 additions and 21 deletions
8
tests/ui/cstring.rs
Normal file
8
tests/ui/cstring.rs
Normal file
|
@ -0,0 +1,8 @@
|
|||
fn main() {}
|
||||
|
||||
#[allow(result_unwrap_used)]
|
||||
fn temporary_cstring() {
|
||||
use std::ffi::CString;
|
||||
|
||||
CString::new("foo").unwrap().as_ptr();
|
||||
}
|
22
tests/ui/cstring.stderr
Normal file
22
tests/ui/cstring.stderr
Normal file
|
@ -0,0 +1,22 @@
|
|||
error: function is never used: `temporary_cstring`
|
||||
--> $DIR/cstring.rs:4:1
|
||||
|
|
||||
4 | fn temporary_cstring() {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `-D dead-code` implied by `-D warnings`
|
||||
|
||||
error: you are getting the inner pointer of a temporary `CString`
|
||||
--> $DIR/cstring.rs:7:5
|
||||
|
|
||||
7 | CString::new("foo").unwrap().as_ptr();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `-D temporary-cstring-as-ptr` implied by `-D warnings`
|
||||
= note: that pointer will be invalid outside this expression
|
||||
help: assign the `CString` to a variable to extend its lifetime
|
||||
--> $DIR/cstring.rs:7:5
|
||||
|
|
||||
7 | CString::new("foo").unwrap().as_ptr();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
@ -453,10 +453,3 @@ fn str_extend_chars() {
|
|||
let f = HasChars;
|
||||
s.extend(f.chars());
|
||||
}
|
||||
|
||||
#[allow(result_unwrap_used)]
|
||||
fn temporary_cstring() {
|
||||
use std::ffi::CString;
|
||||
|
||||
CString::new("foo").unwrap().as_ptr();
|
||||
}
|
||||
|
|
|
@ -567,17 +567,3 @@ error: calling `.extend(_.chars())`
|
|||
447 | s.extend(def.chars());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ help: try this: `s.push_str(&def)`
|
||||
|
||||
error: you are getting the inner pointer of a temporary `CString`
|
||||
--> $DIR/methods.rs:461:5
|
||||
|
|
||||
461 | CString::new("foo").unwrap().as_ptr();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `-D temporary-cstring-as-ptr` implied by `-D warnings`
|
||||
= note: that pointer will be invalid outside this expression
|
||||
help: assign the `CString` to a variable to extend its lifetime
|
||||
--> $DIR/methods.rs:461:5
|
||||
|
|
||||
461 | CString::new("foo").unwrap().as_ptr();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
|
|
Loading…
Reference in a new issue