Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit a2f4afe

Browse files
committed
Add basic test
1 parent 8cf1b0e commit a2f4afe

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+

0 commit comments

Comments
 (0)