You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on May 28, 2025. It is now read-only.
.build("you are getting the inner pointer of a temporary `CString`");
91
-
diag.note("that pointer will be invalid outside this expression");
75
+
.build("getting the inner pointer of a temporary `CString`");
76
+
diag.span_label(source.span,"this pointer will be invalid");
92
77
diag.span_help(
93
78
unwrap.span,
94
-
"assign the `CString` to a variable to extend its lifetime",
79
+
"this `CString` is deallocated at the end of the expression, bind it to a variable to extend its lifetime",
95
80
);
81
+
diag.note("pointers do not have a lifetime; when calling `as_ptr` the `CString` is deallocated because nothing is referencing it as far as the type system is concerned");
error: you are getting the inner pointer of a temporary `CString`
2
-
--> $DIR/lint-temporary-cstring-as-ptr.rs:7:13
1
+
error: getting the inner pointer of a temporary `CString`
2
+
--> $DIR/lint-temporary-cstring-as-ptr.rs:6:13
3
3
|
4
4
LL | let s = CString::new("some text").unwrap().as_ptr();
5
-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5
+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ this pointer will be invalid
6
6
|
7
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
8
+
help: this `CString` is deallocated at the end of the expression, bind it to a variable to extend its lifetime
9
+
--> $DIR/lint-temporary-cstring-as-ptr.rs:6:13
11
10
|
12
11
LL | let s = CString::new("some text").unwrap().as_ptr();
13
12
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13
+
= note: pointers do not have a lifetime; when calling `as_ptr` the `CString` is deallocated because nothing is referencing it as far as the type system is concerned
0 commit comments