Skip to content

Commit cb8b901

Browse files
committed
Address review comments
1 parent 6ba127d commit cb8b901

5 files changed

+8
-9
lines changed

library/std/src/ffi/c_str.rs

-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ use crate::sys;
109109
/// documentation of `CString` before use, as improper ownership management
110110
/// of `CString` instances can lead to invalid memory accesses, memory leaks,
111111
/// and other memory errors.
112-
113112
#[derive(PartialEq, PartialOrd, Eq, Ord, Hash, Clone)]
114113
#[cfg_attr(not(test), rustc_diagnostic_item = "cstring_type")]
115114
#[stable(feature = "rust1", since = "1.0.0")]
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
// ignore-tidy-linelength
21
#![deny(temporary_cstring_as_ptr)]
32

43
use std::ffi::CString;
54

65
fn some_function(data: *const i8) {}
76

87
fn main() {
9-
some_function(CString::new("").unwrap().as_ptr()); //~ ERROR getting the inner pointer of a temporary `CString`
8+
some_function(CString::new("").unwrap().as_ptr());
9+
//~^ ERROR getting the inner pointer of a temporary `CString`
1010
}

src/test/ui/lint/lint-temporary-cstring-as-param.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
error: getting the inner pointer of a temporary `CString`
2-
--> $DIR/lint-temporary-cstring-as-param.rs:9:45
2+
--> $DIR/lint-temporary-cstring-as-param.rs:8:45
33
|
44
LL | some_function(CString::new("").unwrap().as_ptr());
55
| ------------------------- ^^^^^^ this pointer will be invalid
66
| |
77
| this `CString` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
88
|
99
note: the lint level is defined here
10-
--> $DIR/lint-temporary-cstring-as-param.rs:2:9
10+
--> $DIR/lint-temporary-cstring-as-param.rs:1:9
1111
|
1212
LL | #![deny(temporary_cstring_as_ptr)]
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
// ignore-tidy-linelength
21
// this program is not technically incorrect, but is an obscure enough style to be worth linting
32
#![deny(temporary_cstring_as_ptr)]
43

54
use std::ffi::CString;
65

76
fn main() {
8-
let s = CString::new("some text").unwrap().as_ptr(); //~ ERROR getting the inner pointer of a temporary `CString`
7+
let s = CString::new("some text").unwrap().as_ptr();
8+
//~^ ERROR getting the inner pointer of a temporary `CString`
99
}

src/test/ui/lint/lint-temporary-cstring-as-ptr.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
error: getting the inner pointer of a temporary `CString`
2-
--> $DIR/lint-temporary-cstring-as-ptr.rs:8:48
2+
--> $DIR/lint-temporary-cstring-as-ptr.rs:7:48
33
|
44
LL | let s = CString::new("some text").unwrap().as_ptr();
55
| ---------------------------------- ^^^^^^ this pointer will be invalid
66
| |
77
| this `CString` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
88
|
99
note: the lint level is defined here
10-
--> $DIR/lint-temporary-cstring-as-ptr.rs:3:9
10+
--> $DIR/lint-temporary-cstring-as-ptr.rs:2:9
1111
|
1212
LL | #![deny(temporary_cstring_as_ptr)]
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)