Address review comments

This commit is contained in:
Nathan Whitaker 2020-10-26 19:19:06 -04:00
parent 6ba127d3f0
commit cb8b9012db
5 changed files with 8 additions and 9 deletions

View File

@ -109,7 +109,6 @@ use crate::sys;
/// documentation of `CString` before use, as improper ownership management
/// of `CString` instances can lead to invalid memory accesses, memory leaks,
/// and other memory errors.
#[derive(PartialEq, PartialOrd, Eq, Ord, Hash, Clone)]
#[cfg_attr(not(test), rustc_diagnostic_item = "cstring_type")]
#[stable(feature = "rust1", since = "1.0.0")]

View File

@ -1,4 +1,3 @@
// ignore-tidy-linelength
#![deny(temporary_cstring_as_ptr)]
use std::ffi::CString;
@ -6,5 +5,6 @@ use std::ffi::CString;
fn some_function(data: *const i8) {}
fn main() {
some_function(CString::new("").unwrap().as_ptr()); //~ ERROR getting the inner pointer of a temporary `CString`
some_function(CString::new("").unwrap().as_ptr());
//~^ ERROR getting the inner pointer of a temporary `CString`
}

View File

@ -1,5 +1,5 @@
error: getting the inner pointer of a temporary `CString`
--> $DIR/lint-temporary-cstring-as-param.rs:9:45
--> $DIR/lint-temporary-cstring-as-param.rs:8:45
|
LL | some_function(CString::new("").unwrap().as_ptr());
| ------------------------- ^^^^^^ this pointer will be invalid
@ -7,7 +7,7 @@ LL | some_function(CString::new("").unwrap().as_ptr());
| this `CString` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
|
note: the lint level is defined here
--> $DIR/lint-temporary-cstring-as-param.rs:2:9
--> $DIR/lint-temporary-cstring-as-param.rs:1:9
|
LL | #![deny(temporary_cstring_as_ptr)]
| ^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -1,9 +1,9 @@
// ignore-tidy-linelength
// this program is not technically incorrect, but is an obscure enough style to be worth linting
#![deny(temporary_cstring_as_ptr)]
use std::ffi::CString;
fn main() {
let s = CString::new("some text").unwrap().as_ptr(); //~ ERROR 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,5 +1,5 @@
error: getting the inner pointer of a temporary `CString`
--> $DIR/lint-temporary-cstring-as-ptr.rs:8:48
--> $DIR/lint-temporary-cstring-as-ptr.rs:7:48
|
LL | let s = CString::new("some text").unwrap().as_ptr();
| ---------------------------------- ^^^^^^ this pointer will be invalid
@ -7,7 +7,7 @@ LL | let s = CString::new("some text").unwrap().as_ptr();
| this `CString` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
|
note: the lint level is defined here
--> $DIR/lint-temporary-cstring-as-ptr.rs:3:9
--> $DIR/lint-temporary-cstring-as-ptr.rs:2:9
|
LL | #![deny(temporary_cstring_as_ptr)]
| ^^^^^^^^^^^^^^^^^^^^^^^^