59893bcab0
Fixes #4375. Changes the check to test when `.unwrap().as_ptr()` is called on any `Result<CString, _>` as suggested by @flip1995 (https://github.com/rust-lang/rust-clippy/issues/4375#issuecomment-520724123).
47 lines
1.5 KiB
Plaintext
47 lines
1.5 KiB
Plaintext
error: you are getting the inner pointer of a temporary `CString`
|
|
--> $DIR/cstring.rs:8:5
|
|
|
|
|
LL | CString::new("foo").unwrap().as_ptr();
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
note: lint level defined here
|
|
--> $DIR/cstring.rs:1:9
|
|
|
|
|
LL | #![deny(clippy::temporary_cstring_as_ptr)]
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
= note: that pointer will be invalid outside this expression
|
|
help: assign the `CString` to a variable to extend its lifetime
|
|
--> $DIR/cstring.rs:8:5
|
|
|
|
|
LL | CString::new("foo").unwrap().as_ptr();
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
error: you are getting the inner pointer of a temporary `CString`
|
|
--> $DIR/cstring.rs:9:5
|
|
|
|
|
LL | CString::new("foo").expect("dummy").as_ptr();
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
= note: that pointer will be invalid outside this expression
|
|
help: assign the `CString` to a variable to extend its lifetime
|
|
--> $DIR/cstring.rs:9:5
|
|
|
|
|
LL | CString::new("foo").expect("dummy").as_ptr();
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
error: you are getting the inner pointer of a temporary `CString`
|
|
--> $DIR/cstring.rs:22:22
|
|
|
|
|
LL | unsafe { foo(cstr.unwrap().as_ptr()) }
|
|
| ^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
= note: that pointer will be invalid outside this expression
|
|
help: assign the `CString` to a variable to extend its lifetime
|
|
--> $DIR/cstring.rs:22:22
|
|
|
|
|
LL | unsafe { foo(cstr.unwrap().as_ptr()) }
|
|
| ^^^^^^^^^^^^^
|
|
|
|
error: aborting due to 3 previous errors
|
|
|