Add basic test
This commit is contained in:
parent
8cf1b0e1ad
commit
a2f4afe0f6
2 changed files with 24 additions and 0 deletions
8
src/test/ui/lint/lint-temporary-cstring-as-ptr.rs
Normal file
8
src/test/ui/lint/lint-temporary-cstring-as-ptr.rs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
// 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`
|
||||
}
|
||||
16
src/test/ui/lint/lint-temporary-cstring-as-ptr.stderr
Normal file
16
src/test/ui/lint/lint-temporary-cstring-as-ptr.stderr
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
error: you are getting the inner pointer of a temporary `CString`
|
||||
--> $DIR/lint-temporary-cstring-as-ptr.rs:7:13
|
||||
|
|
||||
LL | let s = CString::new("some text").unwrap().as_ptr();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= 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
|
||||
|
|
||||
LL | let s = CString::new("some text").unwrap().as_ptr();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue