2020-08-18 17:02:23 -04:00
|
|
|
error: getting the inner pointer of a temporary `CString`
|
2020-08-23 14:21:58 -04:00
|
|
|
--> $DIR/lint-temporary-cstring-as-ptr.rs:7:48
|
2020-08-18 12:09:33 -04:00
|
|
|
|
|
|
|
|
LL | let s = CString::new("some text").unwrap().as_ptr();
|
2020-08-18 19:37:50 -04:00
|
|
|
| ---------------------------------- ^^^^^^ this pointer will be invalid
|
|
|
|
| |
|
2020-09-21 16:32:28 -04:00
|
|
|
| this `CString` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
|
2020-08-18 12:09:33 -04:00
|
|
|
|
|
2020-08-23 14:21:58 -04:00
|
|
|
note: the lint level is defined here
|
|
|
|
--> $DIR/lint-temporary-cstring-as-ptr.rs:2:9
|
|
|
|
|
|
|
|
|
LL | #![deny(temporary_cstring_as_ptr)]
|
|
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
2020-09-21 16:32:28 -04:00
|
|
|
= note: pointers do not have a lifetime; when calling `as_ptr` the `CString` will be deallocated at the end of the statement...
|
|
|
|
= note: ...because nothing is referencing it as far as the type system is concerned
|
|
|
|
= help: for more information, see https://doc.rust-lang.org/reference/destructors.html
|
2020-08-18 12:09:33 -04:00
|
|
|
|
|
|
|
error: aborting due to previous error
|
|
|
|
|