Address review comments

This commit is contained in:
Nathan Whitaker 2020-08-18 17:02:23 -04:00
parent a2f4afe0f6
commit 8b65df06ce
4 changed files with 48 additions and 57 deletions

View file

@ -1,8 +1,7 @@
// check-fail
// ignore-tidy-linelength
use std::ffi::CString;
fn main() {
let s = CString::new("some text").unwrap().as_ptr(); //~ ERROR you are getting the inner pointer of a temporary `CString`
let s = CString::new("some text").unwrap().as_ptr(); //~ ERROR getting the inner pointer of a temporary `CString`
}

View file

@ -1,16 +1,16 @@
error: you are getting the inner pointer of a temporary `CString`
--> $DIR/lint-temporary-cstring-as-ptr.rs:7:13
error: getting the inner pointer of a temporary `CString`
--> $DIR/lint-temporary-cstring-as-ptr.rs:6:13
|
LL | let s = CString::new("some text").unwrap().as_ptr();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^ this pointer will be invalid
|
= note: `#[deny(temporary_cstring_as_ptr)]` on by default
= note: that pointer will be invalid outside this expression
help: assign the `CString` to a variable to extend its lifetime
--> $DIR/lint-temporary-cstring-as-ptr.rs:7:13
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
|
LL | let s = CString::new("some text").unwrap().as_ptr();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= 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
error: aborting due to previous error