File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change 1+ // check-fail
2+ // ignore-tidy-linelength
3+
4+ use std:: ffi:: CString ;
5+
6+ fn main ( ) {
7+ let s = CString :: new ( "some text" ) . unwrap ( ) . as_ptr ( ) ; //~ ERROR you are getting the inner pointer of a temporary `CString`
8+ }
Original file line number Diff line number Diff line change 1+ error: you are getting the inner pointer of a temporary `CString`
2+ --> $DIR/lint-temporary-cstring-as-ptr.rs:7:13
3+ |
4+ LL | let s = CString::new("some text").unwrap().as_ptr();
5+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+ |
7+ = note: `#[deny(temporary_cstring_as_ptr)]` on by default
8+ = note: that pointer will be invalid outside this expression
9+ help: assign the `CString` to a variable to extend its lifetime
10+ --> $DIR/lint-temporary-cstring-as-ptr.rs:7:13
11+ |
12+ LL | let s = CString::new("some text").unwrap().as_ptr();
13+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14+
15+ error: aborting due to previous error
16+
You can’t perform that action at this time.
0 commit comments