2024-10-16 19:19:56 +00:00
warning: lint `temporary_cstring_as_ptr` has been renamed to `dangling_pointers_from_temporaries`
--> $DIR/cstring-as-ptr.rs:2:9
|
LL | #![deny(temporary_cstring_as_ptr)]
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `dangling_pointers_from_temporaries`
|
= note: `#[warn(renamed_and_removed_lints)]` on by default
error: a dangling pointer will be produced because the temporary `CString` will be dropped
--> $DIR/cstring-as-ptr.rs:15:48
2020-08-18 16:09:33 +00:00
|
LL | let s = CString::new("some text").unwrap().as_ptr();
2024-10-16 19:19:56 +00:00
| ---------------------------------- ^^^^^^ this pointer will immediately be invalid
2020-08-18 23:37:50 +00:00
| |
2020-09-21 20:32:28 +00:00
| this `CString` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
2020-08-18 16:09:33 +00:00
|
2022-09-18 15:55:36 +00:00
= note: pointers do not have a lifetime; when calling `as_ptr` the `CString` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned
2024-10-16 19:19:56 +00:00
= help: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
2020-08-23 18:21:58 +00:00
note: the lint level is defined here
2024-10-16 19:19:56 +00:00
--> $DIR/cstring-as-ptr.rs:2:9
2020-08-23 18:21:58 +00:00
|
LL | #![deny(temporary_cstring_as_ptr)]
| ^^^^^^^^^^^^^^^^^^^^^^^^
2020-08-18 16:09:33 +00:00
2024-10-16 19:19:56 +00:00
error: a dangling pointer will be produced because the temporary `CString` will be dropped
--> $DIR/cstring-as-ptr.rs:9:52
2023-04-04 18:31:25 +00:00
|
LL | let s = CString::new("some text").unwrap().as_ptr();
2024-10-16 19:19:56 +00:00
| ---------------------------------- ^^^^^^ this pointer will immediately be invalid
2023-04-04 18:31:25 +00:00
| |
| this `CString` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
...
LL | mymacro!();
| ---------- in this macro invocation
|
= note: pointers do not have a lifetime; when calling `as_ptr` the `CString` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned
2024-10-16 19:19:56 +00:00
= help: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
2023-04-04 18:31:25 +00:00
= note: this error originates in the macro `mymacro` (in Nightly builds, run with -Z macro-backtrace for more info)
2024-10-16 19:19:56 +00:00
error: aborting due to 2 previous errors; 1 warning emitted
2020-08-18 16:09:33 +00:00