1
Fork 0
rust/src/test/ui/lint/lint-temporary-cstring-as-ptr.stderr

17 lines
799 B
Text
Raw Normal View History

2020-08-18 17:02:23 -04:00
error: getting the inner pointer of a temporary `CString`
--> $DIR/lint-temporary-cstring-as-ptr.rs:6:13
2020-08-18 12:09:33 -04:00
|
LL | let s = CString::new("some text").unwrap().as_ptr();
2020-08-18 17:02:23 -04:00
| ^^^^^^^^^^^^^^^^^^^^^^^^^ this pointer will be invalid
2020-08-18 12:09:33 -04:00
|
= note: `#[deny(temporary_cstring_as_ptr)]` on by default
2020-08-18 17:02:23 -04:00
help: this `CString` is deallocated at the end of the expression, bind it to a variable to extend its lifetime
--> $DIR/lint-temporary-cstring-as-ptr.rs:6:13
2020-08-18 12:09:33 -04:00
|
LL | let s = CString::new("some text").unwrap().as_ptr();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2020-08-18 17:02:23 -04:00
= note: pointers do not have a lifetime; when calling `as_ptr` the `CString` is deallocated because nothing is referencing it as far as the type system is concerned
2020-08-18 12:09:33 -04:00
error: aborting due to previous error