Rollup merge of #148490 - hkBst:dangling-ptr-lint-2, r=Urgau
dangling pointer from temp cleanup Continuation of https://github.com/rust-lang/rust/pull/148348 r? `@Urgau`
This commit is contained in:
commit
d7a18fc052
19 changed files with 354 additions and 332 deletions
|
|
@ -205,15 +205,17 @@ lint_dangling_pointers_from_locals = {$fn_kind} returns a dangling pointer to dr
|
|||
.ret_ty = return type is `{$ret_ty}`
|
||||
.local_var = local variable `{$local_var_name}` is dropped at the end of the {$fn_kind}
|
||||
.created_at = dangling pointer created here
|
||||
.note = a dangling pointer is safe, but dereferencing one is undefined behavior
|
||||
.note_safe = a dangling pointer is safe, but dereferencing one is undefined behavior
|
||||
.note_more_info = for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
|
||||
lint_dangling_pointers_from_temporaries = this creates a dangling pointer because temporary `{$ty}` is dropped at end of statement
|
||||
.label_ptr = pointer created here
|
||||
.label_temporary = this `{$ty}` is dropped at end of statement
|
||||
.help_bind = bind the `{$ty}` to a variable such that it outlives the pointer returned by `{$callee}`
|
||||
.note_safe = a dangling pointer is safe, but dereferencing one is undefined behavior
|
||||
.note_return = returning a pointer to a local variable will always result in a dangling pointer
|
||||
.note_more_info = for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
|
||||
lint_dangling_pointers_from_temporaries = a dangling pointer will be produced because the temporary `{$ty}` will be dropped
|
||||
.label_ptr = this pointer will immediately be invalid
|
||||
.label_temporary = this `{$ty}` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
|
||||
.note = pointers do not have a lifetime; when calling `{$callee}` the `{$ty}` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned
|
||||
.help_bind = you must make sure that the variable you bind the `{$ty}` to lives at least as long as the pointer returned by the call to `{$callee}`
|
||||
.help_returned = in particular, if this pointer is returned from the current function, binding the `{$ty}` inside the function will not suffice
|
||||
.help_visit = for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
|
||||
lint_default_hash_types = prefer `{$preferred}` over `{$used}`, it has better performance
|
||||
.note = a `use rustc_data_structures::fx::{$preferred}` may be necessary
|
||||
|
|
|
|||
|
|
@ -1138,10 +1138,10 @@ pub(crate) struct IgnoredUnlessCrateSpecified<'a> {
|
|||
// dangling.rs
|
||||
#[derive(LintDiagnostic)]
|
||||
#[diag(lint_dangling_pointers_from_temporaries)]
|
||||
#[note]
|
||||
#[help(lint_help_bind)]
|
||||
#[help(lint_help_returned)]
|
||||
#[help(lint_help_visit)]
|
||||
#[note(lint_note_safe)]
|
||||
#[note(lint_note_return)]
|
||||
#[note(lint_note_more_info)]
|
||||
// FIXME: put #[primary_span] on `ptr_span` once it does not cause conflicts
|
||||
pub(crate) struct DanglingPointersFromTemporaries<'tcx> {
|
||||
pub callee: Ident,
|
||||
|
|
@ -1154,7 +1154,8 @@ pub(crate) struct DanglingPointersFromTemporaries<'tcx> {
|
|||
|
||||
#[derive(LintDiagnostic)]
|
||||
#[diag(lint_dangling_pointers_from_locals)]
|
||||
#[note]
|
||||
#[note(lint_note_safe)]
|
||||
#[note(lint_note_more_info)]
|
||||
pub(crate) struct DanglingPointersFromLocals<'tcx> {
|
||||
pub ret_ty: Ty<'tcx>,
|
||||
#[label(lint_ret_ty)]
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ LL | &x
|
|||
| ^^
|
||||
|
|
||||
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
|
||||
= note: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
= note: `#[warn(dangling_pointers_from_locals)]` on by default
|
||||
|
||||
warning: function returns a dangling pointer to dropped local variable `x`
|
||||
|
|
@ -24,6 +25,7 @@ LL | x
|
|||
| ^
|
||||
|
|
||||
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
|
||||
= note: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
|
||||
warning: function returns a dangling pointer to dropped local variable `x`
|
||||
--> $DIR/dangling-pointers-from-locals.rs:24:12
|
||||
|
|
@ -38,6 +40,7 @@ LL | return y;
|
|||
| ^
|
||||
|
|
||||
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
|
||||
= note: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
|
||||
warning: function returns a dangling pointer to dropped local variable `x`
|
||||
--> $DIR/dangling-pointers-from-locals.rs:30:5
|
||||
|
|
@ -52,6 +55,7 @@ LL | &x as *const u8
|
|||
| dangling pointer created here
|
||||
|
|
||||
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
|
||||
= note: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
|
||||
warning: function returns a dangling pointer to dropped local variable `x`
|
||||
--> $DIR/dangling-pointers-from-locals.rs:37:5
|
||||
|
|
@ -66,6 +70,7 @@ LL | x as *const u8
|
|||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
|
||||
= note: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
|
||||
warning: function returns a dangling pointer to dropped local variable `x`
|
||||
--> $DIR/dangling-pointers-from-locals.rs:43:12
|
||||
|
|
@ -80,6 +85,7 @@ LL | return &mut x as *mut u8 as *const u8 as *mut u8;
|
|||
| dangling pointer created here
|
||||
|
|
||||
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
|
||||
= note: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
|
||||
warning: function returns a dangling pointer to dropped local variable `x`
|
||||
--> $DIR/dangling-pointers-from-locals.rs:49:5
|
||||
|
|
@ -92,6 +98,7 @@ LL | &{ x }
|
|||
| ^^^^^^
|
||||
|
|
||||
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
|
||||
= note: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
|
||||
warning: function returns a dangling pointer to dropped local variable `x`
|
||||
--> $DIR/dangling-pointers-from-locals.rs:57:13
|
||||
|
|
@ -108,6 +115,7 @@ LL | | }
|
|||
| |_____________^
|
||||
|
|
||||
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
|
||||
= note: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
|
||||
warning: function returns a dangling pointer to dropped local variable `x`
|
||||
--> $DIR/dangling-pointers-from-locals.rs:67:12
|
||||
|
|
@ -120,6 +128,7 @@ LL | return &x;
|
|||
| ^^
|
||||
|
|
||||
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
|
||||
= note: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
|
||||
warning: function returns a dangling pointer to dropped local variable `x`
|
||||
--> $DIR/dangling-pointers-from-locals.rs:73:12
|
||||
|
|
@ -132,6 +141,7 @@ LL | return &mut x;
|
|||
| ^^^^^^
|
||||
|
|
||||
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
|
||||
= note: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
|
||||
warning: function returns a dangling pointer to dropped local variable `x`
|
||||
--> $DIR/dangling-pointers-from-locals.rs:80:16
|
||||
|
|
@ -145,6 +155,7 @@ LL | return &x;
|
|||
| ^^
|
||||
|
|
||||
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
|
||||
= note: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
|
||||
warning: function returns a dangling pointer to dropped local variable `x`
|
||||
--> $DIR/dangling-pointers-from-locals.rs:88:5
|
||||
|
|
@ -157,6 +168,7 @@ LL | &x
|
|||
| ^^
|
||||
|
|
||||
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
|
||||
= note: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
|
||||
warning: function returns a dangling pointer to dropped local variable `x`
|
||||
--> $DIR/dangling-pointers-from-locals.rs:94:12
|
||||
|
|
@ -169,6 +181,7 @@ LL | return &x;
|
|||
| ^^
|
||||
|
|
||||
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
|
||||
= note: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
|
||||
warning: closure returns a dangling pointer to dropped local variable `x`
|
||||
--> $DIR/dangling-pointers-from-locals.rs:101:16
|
||||
|
|
@ -181,6 +194,7 @@ LL | return &x;
|
|||
| ^^
|
||||
|
|
||||
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
|
||||
= note: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
|
||||
warning: function returns a dangling pointer to dropped local variable `x`
|
||||
--> $DIR/dangling-pointers-from-locals.rs:113:5
|
||||
|
|
@ -194,6 +208,7 @@ LL | &x
|
|||
| ^^
|
||||
|
|
||||
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
|
||||
= note: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
|
||||
warning: function returns a dangling pointer to dropped local variable `a`
|
||||
--> $DIR/dangling-pointers-from-locals.rs:118:5
|
||||
|
|
@ -206,6 +221,7 @@ LL | &a
|
|||
| ^^
|
||||
|
|
||||
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
|
||||
= note: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
|
||||
warning: function returns a dangling pointer to dropped local variable `a`
|
||||
--> $DIR/dangling-pointers-from-locals.rs:123:5
|
||||
|
|
@ -218,6 +234,7 @@ LL | &a
|
|||
| ^^
|
||||
|
|
||||
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
|
||||
= note: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
|
||||
warning: function returns a dangling pointer to dropped local variable `a`
|
||||
--> $DIR/dangling-pointers-from-locals.rs:128:5
|
||||
|
|
@ -230,6 +247,7 @@ LL | &a
|
|||
| ^^
|
||||
|
|
||||
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
|
||||
= note: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
|
||||
warning: function returns a dangling pointer to dropped local variable `a`
|
||||
--> $DIR/dangling-pointers-from-locals.rs:133:5
|
||||
|
|
@ -242,6 +260,7 @@ LL | &a
|
|||
| ^^
|
||||
|
|
||||
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
|
||||
= note: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
|
||||
warning: 19 warnings emitted
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ fn main() {
|
|||
#[deny(dangling_pointers_from_temporaries)]
|
||||
{
|
||||
dbg!(String::new().as_ptr());
|
||||
//~^ ERROR a dangling pointer will be produced because the temporary `String` will be dropped
|
||||
//~^ ERROR dangling pointer
|
||||
}
|
||||
S.foo()
|
||||
}
|
||||
|
|
@ -18,6 +18,6 @@ impl S {
|
|||
#[warn(dangling_pointers_from_temporaries)]
|
||||
fn foo(self) {
|
||||
dbg!(String::new().as_ptr());
|
||||
//~^ WARNING a dangling pointer will be produced because the temporary `String` will be dropped
|
||||
//~^ WARNING dangling pointer
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,33 +1,33 @@
|
|||
error: a dangling pointer will be produced because the temporary `String` will be dropped
|
||||
error: this creates a dangling pointer because temporary `String` is dropped at end of statement
|
||||
--> $DIR/allow.rs:9:28
|
||||
|
|
||||
LL | dbg!(String::new().as_ptr());
|
||||
| ------------- ^^^^^^ this pointer will immediately be invalid
|
||||
| ------------- ^^^^^^ pointer created here
|
||||
| |
|
||||
| this `String` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
|
||||
| this `String` is dropped at end of statement
|
||||
|
|
||||
= note: pointers do not have a lifetime; when calling `as_ptr` the `String` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned
|
||||
= help: you must make sure that the variable you bind the `String` to lives at least as long as the pointer returned by the call to `as_ptr`
|
||||
= help: in particular, if this pointer is returned from the current function, binding the `String` inside the function will not suffice
|
||||
= help: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
= help: bind the `String` to a variable such that it outlives the pointer returned by `as_ptr`
|
||||
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
|
||||
= note: returning a pointer to a local variable will always result in a dangling pointer
|
||||
= note: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
note: the lint level is defined here
|
||||
--> $DIR/allow.rs:7:12
|
||||
|
|
||||
LL | #[deny(dangling_pointers_from_temporaries)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
warning: a dangling pointer will be produced because the temporary `String` will be dropped
|
||||
warning: this creates a dangling pointer because temporary `String` is dropped at end of statement
|
||||
--> $DIR/allow.rs:20:28
|
||||
|
|
||||
LL | dbg!(String::new().as_ptr());
|
||||
| ------------- ^^^^^^ this pointer will immediately be invalid
|
||||
| ------------- ^^^^^^ pointer created here
|
||||
| |
|
||||
| this `String` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
|
||||
| this `String` is dropped at end of statement
|
||||
|
|
||||
= note: pointers do not have a lifetime; when calling `as_ptr` the `String` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned
|
||||
= help: you must make sure that the variable you bind the `String` to lives at least as long as the pointer returned by the call to `as_ptr`
|
||||
= help: in particular, if this pointer is returned from the current function, binding the `String` inside the function will not suffice
|
||||
= help: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
= help: bind the `String` to a variable such that it outlives the pointer returned by `as_ptr`
|
||||
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
|
||||
= note: returning a pointer to a local variable will always result in a dangling pointer
|
||||
= note: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
note: the lint level is defined here
|
||||
--> $DIR/allow.rs:18:12
|
||||
|
|
||||
|
|
|
|||
|
|
@ -25,12 +25,12 @@ fn ok() {
|
|||
fn not_ok() {
|
||||
{
|
||||
let ptr = cstring().as_ptr();
|
||||
//~^ ERROR a dangling pointer will be produced because the temporary `CString` will be dropped
|
||||
//~^ ERROR dangling pointer
|
||||
consume(ptr);
|
||||
}
|
||||
consume({
|
||||
let ptr = cstring().as_ptr();
|
||||
//~^ ERROR a dangling pointer will be produced because the temporary `CString` will be dropped
|
||||
//~^ ERROR dangling pointer
|
||||
ptr
|
||||
});
|
||||
consume({
|
||||
|
|
@ -39,11 +39,11 @@ fn not_ok() {
|
|||
//^ FIXME: should error
|
||||
});
|
||||
let _ptr: *const u8 = cstring().as_ptr().cast();
|
||||
//~^ ERROR a dangling pointer will be produced because the temporary `CString` will be dropped
|
||||
//~^ ERROR dangling pointer
|
||||
let _ptr: *const u8 = { cstring() }.as_ptr().cast();
|
||||
//~^ ERROR a dangling pointer will be produced because the temporary `CString` will be dropped
|
||||
//~^ ERROR dangling pointer
|
||||
let _ptr: *const u8 = { cstring().as_ptr() }.cast();
|
||||
//~^ ERROR a dangling pointer will be produced because the temporary `CString` will be dropped
|
||||
//~^ ERROR dangling pointer
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
|
|
|||
|
|
@ -1,72 +1,72 @@
|
|||
error: a dangling pointer will be produced because the temporary `CString` will be dropped
|
||||
error: this creates a dangling pointer because temporary `CString` is dropped at end of statement
|
||||
--> $DIR/calls.rs:27:29
|
||||
|
|
||||
LL | let ptr = cstring().as_ptr();
|
||||
| --------- ^^^^^^ this pointer will immediately be invalid
|
||||
| --------- ^^^^^^ pointer created here
|
||||
| |
|
||||
| this `CString` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
|
||||
| this `CString` is dropped at end of statement
|
||||
|
|
||||
= note: pointers do not have a lifetime; when calling `as_ptr` the `CString` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned
|
||||
= help: you must make sure that the variable you bind the `CString` to lives at least as long as the pointer returned by the call to `as_ptr`
|
||||
= help: in particular, if this pointer is returned from the current function, binding the `CString` inside the function will not suffice
|
||||
= help: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
= help: bind the `CString` to a variable such that it outlives the pointer returned by `as_ptr`
|
||||
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
|
||||
= note: returning a pointer to a local variable will always result in a dangling pointer
|
||||
= note: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
note: the lint level is defined here
|
||||
--> $DIR/calls.rs:1:9
|
||||
|
|
||||
LL | #![deny(dangling_pointers_from_temporaries)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: a dangling pointer will be produced because the temporary `CString` will be dropped
|
||||
error: this creates a dangling pointer because temporary `CString` is dropped at end of statement
|
||||
--> $DIR/calls.rs:32:29
|
||||
|
|
||||
LL | let ptr = cstring().as_ptr();
|
||||
| --------- ^^^^^^ this pointer will immediately be invalid
|
||||
| --------- ^^^^^^ pointer created here
|
||||
| |
|
||||
| this `CString` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
|
||||
| this `CString` is dropped at end of statement
|
||||
|
|
||||
= note: pointers do not have a lifetime; when calling `as_ptr` the `CString` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned
|
||||
= help: you must make sure that the variable you bind the `CString` to lives at least as long as the pointer returned by the call to `as_ptr`
|
||||
= help: in particular, if this pointer is returned from the current function, binding the `CString` inside the function will not suffice
|
||||
= help: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
= help: bind the `CString` to a variable such that it outlives the pointer returned by `as_ptr`
|
||||
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
|
||||
= note: returning a pointer to a local variable will always result in a dangling pointer
|
||||
= note: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
|
||||
error: a dangling pointer will be produced because the temporary `CString` will be dropped
|
||||
error: this creates a dangling pointer because temporary `CString` is dropped at end of statement
|
||||
--> $DIR/calls.rs:41:37
|
||||
|
|
||||
LL | let _ptr: *const u8 = cstring().as_ptr().cast();
|
||||
| --------- ^^^^^^ this pointer will immediately be invalid
|
||||
| --------- ^^^^^^ pointer created here
|
||||
| |
|
||||
| this `CString` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
|
||||
| this `CString` is dropped at end of statement
|
||||
|
|
||||
= note: pointers do not have a lifetime; when calling `as_ptr` the `CString` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned
|
||||
= help: you must make sure that the variable you bind the `CString` to lives at least as long as the pointer returned by the call to `as_ptr`
|
||||
= help: in particular, if this pointer is returned from the current function, binding the `CString` inside the function will not suffice
|
||||
= help: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
= help: bind the `CString` to a variable such that it outlives the pointer returned by `as_ptr`
|
||||
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
|
||||
= note: returning a pointer to a local variable will always result in a dangling pointer
|
||||
= note: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
|
||||
error: a dangling pointer will be produced because the temporary `CString` will be dropped
|
||||
error: this creates a dangling pointer because temporary `CString` is dropped at end of statement
|
||||
--> $DIR/calls.rs:43:41
|
||||
|
|
||||
LL | let _ptr: *const u8 = { cstring() }.as_ptr().cast();
|
||||
| ------------- ^^^^^^ this pointer will immediately be invalid
|
||||
| ------------- ^^^^^^ pointer created here
|
||||
| |
|
||||
| this `CString` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
|
||||
| this `CString` is dropped at end of statement
|
||||
|
|
||||
= note: pointers do not have a lifetime; when calling `as_ptr` the `CString` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned
|
||||
= help: you must make sure that the variable you bind the `CString` to lives at least as long as the pointer returned by the call to `as_ptr`
|
||||
= help: in particular, if this pointer is returned from the current function, binding the `CString` inside the function will not suffice
|
||||
= help: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
= help: bind the `CString` to a variable such that it outlives the pointer returned by `as_ptr`
|
||||
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
|
||||
= note: returning a pointer to a local variable will always result in a dangling pointer
|
||||
= note: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
|
||||
error: a dangling pointer will be produced because the temporary `CString` will be dropped
|
||||
error: this creates a dangling pointer because temporary `CString` is dropped at end of statement
|
||||
--> $DIR/calls.rs:45:39
|
||||
|
|
||||
LL | let _ptr: *const u8 = { cstring().as_ptr() }.cast();
|
||||
| --------- ^^^^^^ this pointer will immediately be invalid
|
||||
| --------- ^^^^^^ pointer created here
|
||||
| |
|
||||
| this `CString` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
|
||||
| this `CString` is dropped at end of statement
|
||||
|
|
||||
= note: pointers do not have a lifetime; when calling `as_ptr` the `CString` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned
|
||||
= help: you must make sure that the variable you bind the `CString` to lives at least as long as the pointer returned by the call to `as_ptr`
|
||||
= help: in particular, if this pointer is returned from the current function, binding the `CString` inside the function will not suffice
|
||||
= help: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
= help: bind the `CString` to a variable such that it outlives the pointer returned by `as_ptr`
|
||||
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
|
||||
= note: returning a pointer to a local variable will always result in a dangling pointer
|
||||
= note: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -7,12 +7,12 @@ use std::ffi::CString;
|
|||
macro_rules! mymacro {
|
||||
() => {
|
||||
let s = CString::new("some text").unwrap().as_ptr();
|
||||
//~^ ERROR a dangling pointer will be produced because the temporary `CString` will be dropped
|
||||
//~^ ERROR dangling pointer
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let s = CString::new("some text").unwrap().as_ptr();
|
||||
//~^ ERROR a dangling pointer will be produced because the temporary `CString` will be dropped
|
||||
//~^ ERROR dangling pointer
|
||||
mymacro!();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,39 +6,39 @@ LL | #![deny(temporary_cstring_as_ptr)]
|
|||
|
|
||||
= note: `#[warn(renamed_and_removed_lints)]` on by default
|
||||
|
||||
error: a dangling pointer will be produced because the temporary `CString` will be dropped
|
||||
error: this creates a dangling pointer because temporary `CString` is dropped at end of statement
|
||||
--> $DIR/cstring-as-ptr.rs:15:48
|
||||
|
|
||||
LL | let s = CString::new("some text").unwrap().as_ptr();
|
||||
| ---------------------------------- ^^^^^^ this pointer will immediately be invalid
|
||||
| ---------------------------------- ^^^^^^ pointer created here
|
||||
| |
|
||||
| this `CString` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
|
||||
| this `CString` is dropped at end of statement
|
||||
|
|
||||
= note: pointers do not have a lifetime; when calling `as_ptr` the `CString` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned
|
||||
= help: you must make sure that the variable you bind the `CString` to lives at least as long as the pointer returned by the call to `as_ptr`
|
||||
= help: in particular, if this pointer is returned from the current function, binding the `CString` inside the function will not suffice
|
||||
= help: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
= help: bind the `CString` to a variable such that it outlives the pointer returned by `as_ptr`
|
||||
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
|
||||
= note: returning a pointer to a local variable will always result in a dangling pointer
|
||||
= note: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
note: the lint level is defined here
|
||||
--> $DIR/cstring-as-ptr.rs:2:9
|
||||
|
|
||||
LL | #![deny(temporary_cstring_as_ptr)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: a dangling pointer will be produced because the temporary `CString` will be dropped
|
||||
error: this creates a dangling pointer because temporary `CString` is dropped at end of statement
|
||||
--> $DIR/cstring-as-ptr.rs:9:52
|
||||
|
|
||||
LL | let s = CString::new("some text").unwrap().as_ptr();
|
||||
| ---------------------------------- ^^^^^^ this pointer will immediately be invalid
|
||||
| ---------------------------------- ^^^^^^ pointer created here
|
||||
| |
|
||||
| this `CString` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
|
||||
| this `CString` is dropped at end of statement
|
||||
...
|
||||
LL | mymacro!();
|
||||
| ---------- in this macro invocation
|
||||
|
|
||||
= note: pointers do not have a lifetime; when calling `as_ptr` the `CString` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned
|
||||
= help: you must make sure that the variable you bind the `CString` to lives at least as long as the pointer returned by the call to `as_ptr`
|
||||
= help: in particular, if this pointer is returned from the current function, binding the `CString` inside the function will not suffice
|
||||
= help: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
= help: bind the `CString` to a variable such that it outlives the pointer returned by `as_ptr`
|
||||
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
|
||||
= note: returning a pointer to a local variable will always result in a dangling pointer
|
||||
= note: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
= note: this error originates in the macro `mymacro` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: aborting due to 2 previous errors; 1 warning emitted
|
||||
|
|
|
|||
|
|
@ -3,9 +3,9 @@
|
|||
const MAX_PATH: usize = 260;
|
||||
fn main() {
|
||||
let str1 = String::with_capacity(MAX_PATH).as_mut_ptr();
|
||||
//~^ ERROR a dangling pointer will be produced because the temporary `String` will be dropped
|
||||
//~^ ERROR dangling pointer
|
||||
let str2 = String::from("TotototototototototototototototototoT").as_ptr();
|
||||
//~^ ERROR a dangling pointer will be produced because the temporary `String` will be dropped
|
||||
//~^ ERROR dangling pointer
|
||||
unsafe {
|
||||
std::ptr::copy_nonoverlapping(str2, str1, 30);
|
||||
println!("{:?}", String::from_raw_parts(str1, 30, 30));
|
||||
|
|
|
|||
|
|
@ -1,33 +1,33 @@
|
|||
error: a dangling pointer will be produced because the temporary `String` will be dropped
|
||||
error: this creates a dangling pointer because temporary `String` is dropped at end of statement
|
||||
--> $DIR/example-from-issue123613.rs:5:48
|
||||
|
|
||||
LL | let str1 = String::with_capacity(MAX_PATH).as_mut_ptr();
|
||||
| ------------------------------- ^^^^^^^^^^ this pointer will immediately be invalid
|
||||
| ------------------------------- ^^^^^^^^^^ pointer created here
|
||||
| |
|
||||
| this `String` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
|
||||
| this `String` is dropped at end of statement
|
||||
|
|
||||
= note: pointers do not have a lifetime; when calling `as_mut_ptr` the `String` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned
|
||||
= help: you must make sure that the variable you bind the `String` to lives at least as long as the pointer returned by the call to `as_mut_ptr`
|
||||
= help: in particular, if this pointer is returned from the current function, binding the `String` inside the function will not suffice
|
||||
= help: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
= help: bind the `String` to a variable such that it outlives the pointer returned by `as_mut_ptr`
|
||||
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
|
||||
= note: returning a pointer to a local variable will always result in a dangling pointer
|
||||
= note: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
note: the lint level is defined here
|
||||
--> $DIR/example-from-issue123613.rs:1:9
|
||||
|
|
||||
LL | #![deny(dangling_pointers_from_temporaries)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: a dangling pointer will be produced because the temporary `String` will be dropped
|
||||
error: this creates a dangling pointer because temporary `String` is dropped at end of statement
|
||||
--> $DIR/example-from-issue123613.rs:7:70
|
||||
|
|
||||
LL | let str2 = String::from("TotototototototototototototototototoT").as_ptr();
|
||||
| ----------------------------------------------------- ^^^^^^ this pointer will immediately be invalid
|
||||
| ----------------------------------------------------- ^^^^^^ pointer created here
|
||||
| |
|
||||
| this `String` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
|
||||
| this `String` is dropped at end of statement
|
||||
|
|
||||
= note: pointers do not have a lifetime; when calling `as_ptr` the `String` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned
|
||||
= help: you must make sure that the variable you bind the `String` to lives at least as long as the pointer returned by the call to `as_ptr`
|
||||
= help: in particular, if this pointer is returned from the current function, binding the `String` inside the function will not suffice
|
||||
= help: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
= help: bind the `String` to a variable such that it outlives the pointer returned by `as_ptr`
|
||||
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
|
||||
= note: returning a pointer to a local variable will always result in a dangling pointer
|
||||
= note: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ impl Ext2 for *const u32 {
|
|||
|
||||
fn main() {
|
||||
let _ptr1 = Vec::<u32>::new().as_ptr().dbg();
|
||||
//~^ ERROR a dangling pointer will be produced because the temporary `Vec<u32>` will be dropped
|
||||
//~^ ERROR dangling pointer
|
||||
let _ptr2 = vec![0].as_ptr().foo();
|
||||
//~^ ERROR a dangling pointer will be produced because the temporary `Vec<u32>` will be dropped
|
||||
//~^ ERROR dangling pointer
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,33 +1,33 @@
|
|||
error: a dangling pointer will be produced because the temporary `Vec<u32>` will be dropped
|
||||
error: this creates a dangling pointer because temporary `Vec<u32>` is dropped at end of statement
|
||||
--> $DIR/ext.rs:28:35
|
||||
|
|
||||
LL | let _ptr1 = Vec::<u32>::new().as_ptr().dbg();
|
||||
| ----------------- ^^^^^^ this pointer will immediately be invalid
|
||||
| ----------------- ^^^^^^ pointer created here
|
||||
| |
|
||||
| this `Vec<u32>` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
|
||||
| this `Vec<u32>` is dropped at end of statement
|
||||
|
|
||||
= note: pointers do not have a lifetime; when calling `as_ptr` the `Vec<u32>` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned
|
||||
= help: you must make sure that the variable you bind the `Vec<u32>` to lives at least as long as the pointer returned by the call to `as_ptr`
|
||||
= help: in particular, if this pointer is returned from the current function, binding the `Vec<u32>` inside the function will not suffice
|
||||
= help: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
= help: bind the `Vec<u32>` to a variable such that it outlives the pointer returned by `as_ptr`
|
||||
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
|
||||
= note: returning a pointer to a local variable will always result in a dangling pointer
|
||||
= note: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
note: the lint level is defined here
|
||||
--> $DIR/ext.rs:1:9
|
||||
|
|
||||
LL | #![deny(dangling_pointers_from_temporaries)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: a dangling pointer will be produced because the temporary `Vec<u32>` will be dropped
|
||||
error: this creates a dangling pointer because temporary `Vec<u32>` is dropped at end of statement
|
||||
--> $DIR/ext.rs:30:25
|
||||
|
|
||||
LL | let _ptr2 = vec![0].as_ptr().foo();
|
||||
| ------- ^^^^^^ this pointer will immediately be invalid
|
||||
| ------- ^^^^^^ pointer created here
|
||||
| |
|
||||
| this `Vec<u32>` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
|
||||
| this `Vec<u32>` is dropped at end of statement
|
||||
|
|
||||
= note: pointers do not have a lifetime; when calling `as_ptr` the `Vec<u32>` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned
|
||||
= help: you must make sure that the variable you bind the `Vec<u32>` to lives at least as long as the pointer returned by the call to `as_ptr`
|
||||
= help: in particular, if this pointer is returned from the current function, binding the `Vec<u32>` inside the function will not suffice
|
||||
= help: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
= help: bind the `Vec<u32>` to a variable such that it outlives the pointer returned by `as_ptr`
|
||||
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
|
||||
= note: returning a pointer to a local variable will always result in a dangling pointer
|
||||
= note: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
fn main() {
|
||||
vec![0u8].as_ptr();
|
||||
//~^ ERROR a dangling pointer will be produced because the temporary `Vec<u8>` will be dropped
|
||||
//~^ ERROR dangling pointer
|
||||
vec![0u8].as_mut_ptr();
|
||||
//~^ ERROR a dangling pointer will be produced because the temporary `Vec<u8>` will be dropped
|
||||
//~^ ERROR dangling pointer
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,33 +1,33 @@
|
|||
error: a dangling pointer will be produced because the temporary `Vec<u8>` will be dropped
|
||||
error: this creates a dangling pointer because temporary `Vec<u8>` is dropped at end of statement
|
||||
--> $DIR/methods.rs:4:15
|
||||
|
|
||||
LL | vec![0u8].as_ptr();
|
||||
| --------- ^^^^^^ this pointer will immediately be invalid
|
||||
| --------- ^^^^^^ pointer created here
|
||||
| |
|
||||
| this `Vec<u8>` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
|
||||
| this `Vec<u8>` is dropped at end of statement
|
||||
|
|
||||
= note: pointers do not have a lifetime; when calling `as_ptr` the `Vec<u8>` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned
|
||||
= help: you must make sure that the variable you bind the `Vec<u8>` to lives at least as long as the pointer returned by the call to `as_ptr`
|
||||
= help: in particular, if this pointer is returned from the current function, binding the `Vec<u8>` inside the function will not suffice
|
||||
= help: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
= help: bind the `Vec<u8>` to a variable such that it outlives the pointer returned by `as_ptr`
|
||||
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
|
||||
= note: returning a pointer to a local variable will always result in a dangling pointer
|
||||
= note: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
note: the lint level is defined here
|
||||
--> $DIR/methods.rs:1:9
|
||||
|
|
||||
LL | #![deny(dangling_pointers_from_temporaries)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: a dangling pointer will be produced because the temporary `Vec<u8>` will be dropped
|
||||
error: this creates a dangling pointer because temporary `Vec<u8>` is dropped at end of statement
|
||||
--> $DIR/methods.rs:6:15
|
||||
|
|
||||
LL | vec![0u8].as_mut_ptr();
|
||||
| --------- ^^^^^^^^^^ this pointer will immediately be invalid
|
||||
| --------- ^^^^^^^^^^ pointer created here
|
||||
| |
|
||||
| this `Vec<u8>` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
|
||||
| this `Vec<u8>` is dropped at end of statement
|
||||
|
|
||||
= note: pointers do not have a lifetime; when calling `as_mut_ptr` the `Vec<u8>` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned
|
||||
= help: you must make sure that the variable you bind the `Vec<u8>` to lives at least as long as the pointer returned by the call to `as_mut_ptr`
|
||||
= help: in particular, if this pointer is returned from the current function, binding the `Vec<u8>` inside the function will not suffice
|
||||
= help: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
= help: bind the `Vec<u8>` to a variable such that it outlives the pointer returned by `as_mut_ptr`
|
||||
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
|
||||
= note: returning a pointer to a local variable will always result in a dangling pointer
|
||||
= note: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -19,18 +19,18 @@ fn main() {
|
|||
|
||||
// Call
|
||||
string().as_ptr();
|
||||
//~^ ERROR a dangling pointer will be produced because the temporary `String` will be dropped
|
||||
//~^ ERROR dangling pointer
|
||||
|
||||
// MethodCall
|
||||
"hello".to_string().as_ptr();
|
||||
//~^ ERROR a dangling pointer will be produced because the temporary `String` will be dropped
|
||||
//~^ ERROR dangling pointer
|
||||
|
||||
// Tup
|
||||
// impossible
|
||||
|
||||
// Binary
|
||||
(string() + "hello").as_ptr();
|
||||
//~^ ERROR a dangling pointer will be produced because the temporary `String` will be dropped
|
||||
//~^ ERROR dangling pointer
|
||||
|
||||
// Path
|
||||
{
|
||||
|
|
@ -66,7 +66,7 @@ fn main() {
|
|||
// If
|
||||
{
|
||||
(if true { String::new() } else { "hello".into() }).as_ptr();
|
||||
//~^ ERROR a dangling pointer will be produced because the temporary `String` will be dropped
|
||||
//~^ ERROR dangling pointer
|
||||
}
|
||||
|
||||
// Loop
|
||||
|
|
@ -75,7 +75,7 @@ fn main() {
|
|||
break String::new();
|
||||
})
|
||||
.as_ptr();
|
||||
//~^ ERROR a dangling pointer will be produced because the temporary `String` will be dropped
|
||||
//~^ ERROR dangling pointer
|
||||
}
|
||||
|
||||
// Match
|
||||
|
|
@ -84,7 +84,7 @@ fn main() {
|
|||
s => s,
|
||||
}
|
||||
.as_ptr();
|
||||
//~^ ERROR a dangling pointer will be produced because the temporary `String` will be dropped
|
||||
//~^ ERROR dangling pointer
|
||||
}
|
||||
|
||||
// Closure
|
||||
|
|
@ -92,7 +92,7 @@ fn main() {
|
|||
|
||||
// Block
|
||||
{ string() }.as_ptr();
|
||||
//~^ ERROR a dangling pointer will be produced because the temporary `String` will be dropped
|
||||
//~^ ERROR dangling pointer
|
||||
|
||||
// Assign, AssignOp
|
||||
// impossible
|
||||
|
|
@ -132,5 +132,5 @@ fn main() {
|
|||
|
||||
// Macro
|
||||
vec![0u8].as_ptr();
|
||||
//~^ ERROR a dangling pointer will be produced because the temporary `Vec<u8>` will be dropped
|
||||
//~^ ERROR dangling pointer
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,115 +1,115 @@
|
|||
error: a dangling pointer will be produced because the temporary `String` will be dropped
|
||||
error: this creates a dangling pointer because temporary `String` is dropped at end of statement
|
||||
--> $DIR/temporaries.rs:21:14
|
||||
|
|
||||
LL | string().as_ptr();
|
||||
| -------- ^^^^^^ this pointer will immediately be invalid
|
||||
| -------- ^^^^^^ pointer created here
|
||||
| |
|
||||
| this `String` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
|
||||
| this `String` is dropped at end of statement
|
||||
|
|
||||
= note: pointers do not have a lifetime; when calling `as_ptr` the `String` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned
|
||||
= help: you must make sure that the variable you bind the `String` to lives at least as long as the pointer returned by the call to `as_ptr`
|
||||
= help: in particular, if this pointer is returned from the current function, binding the `String` inside the function will not suffice
|
||||
= help: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
= help: bind the `String` to a variable such that it outlives the pointer returned by `as_ptr`
|
||||
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
|
||||
= note: returning a pointer to a local variable will always result in a dangling pointer
|
||||
= note: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
note: the lint level is defined here
|
||||
--> $DIR/temporaries.rs:2:9
|
||||
|
|
||||
LL | #![deny(dangling_pointers_from_temporaries)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: a dangling pointer will be produced because the temporary `String` will be dropped
|
||||
error: this creates a dangling pointer because temporary `String` is dropped at end of statement
|
||||
--> $DIR/temporaries.rs:25:25
|
||||
|
|
||||
LL | "hello".to_string().as_ptr();
|
||||
| ------------------- ^^^^^^ this pointer will immediately be invalid
|
||||
| ------------------- ^^^^^^ pointer created here
|
||||
| |
|
||||
| this `String` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
|
||||
| this `String` is dropped at end of statement
|
||||
|
|
||||
= note: pointers do not have a lifetime; when calling `as_ptr` the `String` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned
|
||||
= help: you must make sure that the variable you bind the `String` to lives at least as long as the pointer returned by the call to `as_ptr`
|
||||
= help: in particular, if this pointer is returned from the current function, binding the `String` inside the function will not suffice
|
||||
= help: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
= help: bind the `String` to a variable such that it outlives the pointer returned by `as_ptr`
|
||||
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
|
||||
= note: returning a pointer to a local variable will always result in a dangling pointer
|
||||
= note: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
|
||||
error: a dangling pointer will be produced because the temporary `String` will be dropped
|
||||
error: this creates a dangling pointer because temporary `String` is dropped at end of statement
|
||||
--> $DIR/temporaries.rs:32:26
|
||||
|
|
||||
LL | (string() + "hello").as_ptr();
|
||||
| -------------------- ^^^^^^ this pointer will immediately be invalid
|
||||
| -------------------- ^^^^^^ pointer created here
|
||||
| |
|
||||
| this `String` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
|
||||
| this `String` is dropped at end of statement
|
||||
|
|
||||
= note: pointers do not have a lifetime; when calling `as_ptr` the `String` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned
|
||||
= help: you must make sure that the variable you bind the `String` to lives at least as long as the pointer returned by the call to `as_ptr`
|
||||
= help: in particular, if this pointer is returned from the current function, binding the `String` inside the function will not suffice
|
||||
= help: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
= help: bind the `String` to a variable such that it outlives the pointer returned by `as_ptr`
|
||||
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
|
||||
= note: returning a pointer to a local variable will always result in a dangling pointer
|
||||
= note: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
|
||||
error: a dangling pointer will be produced because the temporary `String` will be dropped
|
||||
error: this creates a dangling pointer because temporary `String` is dropped at end of statement
|
||||
--> $DIR/temporaries.rs:68:61
|
||||
|
|
||||
LL | (if true { String::new() } else { "hello".into() }).as_ptr();
|
||||
| --------------------------------------------------- ^^^^^^ this pointer will immediately be invalid
|
||||
| --------------------------------------------------- ^^^^^^ pointer created here
|
||||
| |
|
||||
| this `String` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
|
||||
| this `String` is dropped at end of statement
|
||||
|
|
||||
= note: pointers do not have a lifetime; when calling `as_ptr` the `String` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned
|
||||
= help: you must make sure that the variable you bind the `String` to lives at least as long as the pointer returned by the call to `as_ptr`
|
||||
= help: in particular, if this pointer is returned from the current function, binding the `String` inside the function will not suffice
|
||||
= help: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
= help: bind the `String` to a variable such that it outlives the pointer returned by `as_ptr`
|
||||
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
|
||||
= note: returning a pointer to a local variable will always result in a dangling pointer
|
||||
= note: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
|
||||
error: a dangling pointer will be produced because the temporary `String` will be dropped
|
||||
error: this creates a dangling pointer because temporary `String` is dropped at end of statement
|
||||
--> $DIR/temporaries.rs:77:10
|
||||
|
|
||||
LL | / (loop {
|
||||
LL | | break String::new();
|
||||
LL | | })
|
||||
| |__________- this `String` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
|
||||
| |__________- this `String` is dropped at end of statement
|
||||
LL | .as_ptr();
|
||||
| ^^^^^^ this pointer will immediately be invalid
|
||||
| ^^^^^^ pointer created here
|
||||
|
|
||||
= note: pointers do not have a lifetime; when calling `as_ptr` the `String` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned
|
||||
= help: you must make sure that the variable you bind the `String` to lives at least as long as the pointer returned by the call to `as_ptr`
|
||||
= help: in particular, if this pointer is returned from the current function, binding the `String` inside the function will not suffice
|
||||
= help: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
= help: bind the `String` to a variable such that it outlives the pointer returned by `as_ptr`
|
||||
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
|
||||
= note: returning a pointer to a local variable will always result in a dangling pointer
|
||||
= note: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
|
||||
error: a dangling pointer will be produced because the temporary `String` will be dropped
|
||||
error: this creates a dangling pointer because temporary `String` is dropped at end of statement
|
||||
--> $DIR/temporaries.rs:86:10
|
||||
|
|
||||
LL | / match string() {
|
||||
LL | | s => s,
|
||||
LL | | }
|
||||
| |_________- this `String` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
|
||||
| |_________- this `String` is dropped at end of statement
|
||||
LL | .as_ptr();
|
||||
| ^^^^^^ this pointer will immediately be invalid
|
||||
| ^^^^^^ pointer created here
|
||||
|
|
||||
= note: pointers do not have a lifetime; when calling `as_ptr` the `String` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned
|
||||
= help: you must make sure that the variable you bind the `String` to lives at least as long as the pointer returned by the call to `as_ptr`
|
||||
= help: in particular, if this pointer is returned from the current function, binding the `String` inside the function will not suffice
|
||||
= help: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
= help: bind the `String` to a variable such that it outlives the pointer returned by `as_ptr`
|
||||
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
|
||||
= note: returning a pointer to a local variable will always result in a dangling pointer
|
||||
= note: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
|
||||
error: a dangling pointer will be produced because the temporary `String` will be dropped
|
||||
error: this creates a dangling pointer because temporary `String` is dropped at end of statement
|
||||
--> $DIR/temporaries.rs:94:18
|
||||
|
|
||||
LL | { string() }.as_ptr();
|
||||
| ------------ ^^^^^^ this pointer will immediately be invalid
|
||||
| ------------ ^^^^^^ pointer created here
|
||||
| |
|
||||
| this `String` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
|
||||
| this `String` is dropped at end of statement
|
||||
|
|
||||
= note: pointers do not have a lifetime; when calling `as_ptr` the `String` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned
|
||||
= help: you must make sure that the variable you bind the `String` to lives at least as long as the pointer returned by the call to `as_ptr`
|
||||
= help: in particular, if this pointer is returned from the current function, binding the `String` inside the function will not suffice
|
||||
= help: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
= help: bind the `String` to a variable such that it outlives the pointer returned by `as_ptr`
|
||||
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
|
||||
= note: returning a pointer to a local variable will always result in a dangling pointer
|
||||
= note: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
|
||||
error: a dangling pointer will be produced because the temporary `Vec<u8>` will be dropped
|
||||
error: this creates a dangling pointer because temporary `Vec<u8>` is dropped at end of statement
|
||||
--> $DIR/temporaries.rs:134:15
|
||||
|
|
||||
LL | vec![0u8].as_ptr();
|
||||
| --------- ^^^^^^ this pointer will immediately be invalid
|
||||
| --------- ^^^^^^ pointer created here
|
||||
| |
|
||||
| this `Vec<u8>` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
|
||||
| this `Vec<u8>` is dropped at end of statement
|
||||
|
|
||||
= note: pointers do not have a lifetime; when calling `as_ptr` the `Vec<u8>` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned
|
||||
= help: you must make sure that the variable you bind the `Vec<u8>` to lives at least as long as the pointer returned by the call to `as_ptr`
|
||||
= help: in particular, if this pointer is returned from the current function, binding the `Vec<u8>` inside the function will not suffice
|
||||
= help: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
= help: bind the `Vec<u8>` to a variable such that it outlives the pointer returned by `as_ptr`
|
||||
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
|
||||
= note: returning a pointer to a local variable will always result in a dangling pointer
|
||||
= note: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
|
||||
error: aborting due to 8 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -19,39 +19,39 @@ fn declval<T>() -> T {
|
|||
|
||||
fn main() {
|
||||
declval::<CString>().as_ptr();
|
||||
//~^ ERROR a dangling pointer will be produced because the temporary `CString` will be dropped
|
||||
//~^ ERROR dangling pointer because temporary `CString`
|
||||
declval::<String>().as_ptr();
|
||||
//~^ ERROR a dangling pointer will be produced because the temporary `String` will be dropped
|
||||
//~^ ERROR dangling pointer because temporary `String`
|
||||
declval::<Vec<u8>>().as_ptr();
|
||||
//~^ ERROR a dangling pointer will be produced because the temporary `Vec<u8>` will be dropped
|
||||
//~^ ERROR dangling pointer because temporary `Vec<u8>`
|
||||
declval::<Box<CString>>().as_ptr();
|
||||
//~^ ERROR a dangling pointer will be produced because the temporary `Box<CString>` will be dropped
|
||||
//~^ ERROR dangling pointer because temporary `Box<CString>`
|
||||
declval::<Box<[u8]>>().as_ptr();
|
||||
//~^ ERROR a dangling pointer will be produced because the temporary `Box<[u8]>` will be dropped
|
||||
//~^ ERROR dangling pointer because temporary `Box<[u8]>`
|
||||
declval::<Box<str>>().as_ptr();
|
||||
//~^ ERROR a dangling pointer will be produced because the temporary `Box<str>` will be dropped
|
||||
//~^ ERROR dangling pointer because temporary `Box<str>`
|
||||
declval::<Box<CStr>>().as_ptr();
|
||||
//~^ ERROR a dangling pointer will be produced because the temporary `Box<CStr>` will be dropped
|
||||
//~^ ERROR dangling pointer because temporary `Box<CStr>`
|
||||
declval::<[u8; 10]>().as_ptr();
|
||||
//~^ ERROR a dangling pointer will be produced because the temporary `[u8; 10]` will be dropped
|
||||
//~^ ERROR dangling pointer because temporary `[u8; 10]`
|
||||
declval::<Box<[u8; 10]>>().as_ptr();
|
||||
//~^ ERROR a dangling pointer will be produced because the temporary `Box<[u8; 10]>` will be dropped
|
||||
//~^ ERROR dangling pointer because temporary `Box<[u8; 10]>`
|
||||
declval::<Box<Vec<u8>>>().as_ptr();
|
||||
//~^ ERROR a dangling pointer will be produced because the temporary `Box<Vec<u8>>` will be dropped
|
||||
//~^ ERROR dangling pointer because temporary `Box<Vec<u8>>`
|
||||
declval::<Box<String>>().as_ptr();
|
||||
//~^ ERROR a dangling pointer will be produced because the temporary `Box<String>` will be dropped
|
||||
//~^ ERROR dangling pointer because temporary `Box<String>`
|
||||
declval::<Box<Box<Box<Box<[u8]>>>>>().as_ptr();
|
||||
//~^ ERROR a dangling pointer will be produced because the temporary `Box<Box<Box<Box<[u8]>>>>` will be dropped
|
||||
//~^ ERROR dangling pointer because temporary `Box<Box<Box<Box<[u8]>>>>`
|
||||
declval::<Cell<u8>>().as_ptr();
|
||||
//~^ ERROR a dangling pointer will be produced because the temporary `Cell<u8>` will be dropped
|
||||
//~^ ERROR dangling pointer because temporary `Cell<u8>`
|
||||
declval::<MaybeUninit<u8>>().as_ptr();
|
||||
//~^ ERROR a dangling pointer will be produced because the temporary `MaybeUninit<u8>` will be dropped
|
||||
//~^ ERROR dangling pointer because temporary `MaybeUninit<u8>`
|
||||
declval::<Vec<AsPtrFake>>().as_ptr();
|
||||
//~^ ERROR a dangling pointer will be produced because the temporary `Vec<AsPtrFake>` will be dropped
|
||||
//~^ ERROR dangling pointer because temporary `Vec<AsPtrFake>`
|
||||
declval::<UnsafeCell<u8>>().get();
|
||||
//~^ ERROR a dangling pointer will be produced because the temporary `UnsafeCell<u8>` will be dropped
|
||||
//~^ ERROR dangling pointer because temporary `UnsafeCell<u8>`
|
||||
declval::<SyncUnsafeCell<u8>>().get();
|
||||
//~^ ERROR a dangling pointer will be produced because the temporary `SyncUnsafeCell<u8>` will be dropped
|
||||
//~^ ERROR dangling pointer because temporary `SyncUnsafeCell<u8>`
|
||||
declval::<Box<AsPtrFake>>().as_ptr();
|
||||
declval::<AsPtrFake>().as_ptr();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,228 +1,228 @@
|
|||
error: a dangling pointer will be produced because the temporary `CString` will be dropped
|
||||
error: this creates a dangling pointer because temporary `CString` is dropped at end of statement
|
||||
--> $DIR/types.rs:21:26
|
||||
|
|
||||
LL | declval::<CString>().as_ptr();
|
||||
| -------------------- ^^^^^^ this pointer will immediately be invalid
|
||||
| -------------------- ^^^^^^ pointer created here
|
||||
| |
|
||||
| this `CString` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
|
||||
| this `CString` is dropped at end of statement
|
||||
|
|
||||
= note: pointers do not have a lifetime; when calling `as_ptr` the `CString` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned
|
||||
= help: you must make sure that the variable you bind the `CString` to lives at least as long as the pointer returned by the call to `as_ptr`
|
||||
= help: in particular, if this pointer is returned from the current function, binding the `CString` inside the function will not suffice
|
||||
= help: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
= help: bind the `CString` to a variable such that it outlives the pointer returned by `as_ptr`
|
||||
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
|
||||
= note: returning a pointer to a local variable will always result in a dangling pointer
|
||||
= note: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
note: the lint level is defined here
|
||||
--> $DIR/types.rs:1:9
|
||||
|
|
||||
LL | #![deny(dangling_pointers_from_temporaries)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: a dangling pointer will be produced because the temporary `String` will be dropped
|
||||
error: this creates a dangling pointer because temporary `String` is dropped at end of statement
|
||||
--> $DIR/types.rs:23:25
|
||||
|
|
||||
LL | declval::<String>().as_ptr();
|
||||
| ------------------- ^^^^^^ this pointer will immediately be invalid
|
||||
| ------------------- ^^^^^^ pointer created here
|
||||
| |
|
||||
| this `String` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
|
||||
| this `String` is dropped at end of statement
|
||||
|
|
||||
= note: pointers do not have a lifetime; when calling `as_ptr` the `String` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned
|
||||
= help: you must make sure that the variable you bind the `String` to lives at least as long as the pointer returned by the call to `as_ptr`
|
||||
= help: in particular, if this pointer is returned from the current function, binding the `String` inside the function will not suffice
|
||||
= help: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
= help: bind the `String` to a variable such that it outlives the pointer returned by `as_ptr`
|
||||
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
|
||||
= note: returning a pointer to a local variable will always result in a dangling pointer
|
||||
= note: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
|
||||
error: a dangling pointer will be produced because the temporary `Vec<u8>` will be dropped
|
||||
error: this creates a dangling pointer because temporary `Vec<u8>` is dropped at end of statement
|
||||
--> $DIR/types.rs:25:26
|
||||
|
|
||||
LL | declval::<Vec<u8>>().as_ptr();
|
||||
| -------------------- ^^^^^^ this pointer will immediately be invalid
|
||||
| -------------------- ^^^^^^ pointer created here
|
||||
| |
|
||||
| this `Vec<u8>` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
|
||||
| this `Vec<u8>` is dropped at end of statement
|
||||
|
|
||||
= note: pointers do not have a lifetime; when calling `as_ptr` the `Vec<u8>` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned
|
||||
= help: you must make sure that the variable you bind the `Vec<u8>` to lives at least as long as the pointer returned by the call to `as_ptr`
|
||||
= help: in particular, if this pointer is returned from the current function, binding the `Vec<u8>` inside the function will not suffice
|
||||
= help: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
= help: bind the `Vec<u8>` to a variable such that it outlives the pointer returned by `as_ptr`
|
||||
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
|
||||
= note: returning a pointer to a local variable will always result in a dangling pointer
|
||||
= note: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
|
||||
error: a dangling pointer will be produced because the temporary `Box<CString>` will be dropped
|
||||
error: this creates a dangling pointer because temporary `Box<CString>` is dropped at end of statement
|
||||
--> $DIR/types.rs:27:31
|
||||
|
|
||||
LL | declval::<Box<CString>>().as_ptr();
|
||||
| ------------------------- ^^^^^^ this pointer will immediately be invalid
|
||||
| ------------------------- ^^^^^^ pointer created here
|
||||
| |
|
||||
| this `Box<CString>` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
|
||||
| this `Box<CString>` is dropped at end of statement
|
||||
|
|
||||
= note: pointers do not have a lifetime; when calling `as_ptr` the `Box<CString>` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned
|
||||
= help: you must make sure that the variable you bind the `Box<CString>` to lives at least as long as the pointer returned by the call to `as_ptr`
|
||||
= help: in particular, if this pointer is returned from the current function, binding the `Box<CString>` inside the function will not suffice
|
||||
= help: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
= help: bind the `Box<CString>` to a variable such that it outlives the pointer returned by `as_ptr`
|
||||
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
|
||||
= note: returning a pointer to a local variable will always result in a dangling pointer
|
||||
= note: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
|
||||
error: a dangling pointer will be produced because the temporary `Box<[u8]>` will be dropped
|
||||
error: this creates a dangling pointer because temporary `Box<[u8]>` is dropped at end of statement
|
||||
--> $DIR/types.rs:29:28
|
||||
|
|
||||
LL | declval::<Box<[u8]>>().as_ptr();
|
||||
| ---------------------- ^^^^^^ this pointer will immediately be invalid
|
||||
| ---------------------- ^^^^^^ pointer created here
|
||||
| |
|
||||
| this `Box<[u8]>` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
|
||||
| this `Box<[u8]>` is dropped at end of statement
|
||||
|
|
||||
= note: pointers do not have a lifetime; when calling `as_ptr` the `Box<[u8]>` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned
|
||||
= help: you must make sure that the variable you bind the `Box<[u8]>` to lives at least as long as the pointer returned by the call to `as_ptr`
|
||||
= help: in particular, if this pointer is returned from the current function, binding the `Box<[u8]>` inside the function will not suffice
|
||||
= help: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
= help: bind the `Box<[u8]>` to a variable such that it outlives the pointer returned by `as_ptr`
|
||||
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
|
||||
= note: returning a pointer to a local variable will always result in a dangling pointer
|
||||
= note: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
|
||||
error: a dangling pointer will be produced because the temporary `Box<str>` will be dropped
|
||||
error: this creates a dangling pointer because temporary `Box<str>` is dropped at end of statement
|
||||
--> $DIR/types.rs:31:27
|
||||
|
|
||||
LL | declval::<Box<str>>().as_ptr();
|
||||
| --------------------- ^^^^^^ this pointer will immediately be invalid
|
||||
| --------------------- ^^^^^^ pointer created here
|
||||
| |
|
||||
| this `Box<str>` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
|
||||
| this `Box<str>` is dropped at end of statement
|
||||
|
|
||||
= note: pointers do not have a lifetime; when calling `as_ptr` the `Box<str>` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned
|
||||
= help: you must make sure that the variable you bind the `Box<str>` to lives at least as long as the pointer returned by the call to `as_ptr`
|
||||
= help: in particular, if this pointer is returned from the current function, binding the `Box<str>` inside the function will not suffice
|
||||
= help: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
= help: bind the `Box<str>` to a variable such that it outlives the pointer returned by `as_ptr`
|
||||
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
|
||||
= note: returning a pointer to a local variable will always result in a dangling pointer
|
||||
= note: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
|
||||
error: a dangling pointer will be produced because the temporary `Box<CStr>` will be dropped
|
||||
error: this creates a dangling pointer because temporary `Box<CStr>` is dropped at end of statement
|
||||
--> $DIR/types.rs:33:28
|
||||
|
|
||||
LL | declval::<Box<CStr>>().as_ptr();
|
||||
| ---------------------- ^^^^^^ this pointer will immediately be invalid
|
||||
| ---------------------- ^^^^^^ pointer created here
|
||||
| |
|
||||
| this `Box<CStr>` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
|
||||
| this `Box<CStr>` is dropped at end of statement
|
||||
|
|
||||
= note: pointers do not have a lifetime; when calling `as_ptr` the `Box<CStr>` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned
|
||||
= help: you must make sure that the variable you bind the `Box<CStr>` to lives at least as long as the pointer returned by the call to `as_ptr`
|
||||
= help: in particular, if this pointer is returned from the current function, binding the `Box<CStr>` inside the function will not suffice
|
||||
= help: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
= help: bind the `Box<CStr>` to a variable such that it outlives the pointer returned by `as_ptr`
|
||||
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
|
||||
= note: returning a pointer to a local variable will always result in a dangling pointer
|
||||
= note: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
|
||||
error: a dangling pointer will be produced because the temporary `[u8; 10]` will be dropped
|
||||
error: this creates a dangling pointer because temporary `[u8; 10]` is dropped at end of statement
|
||||
--> $DIR/types.rs:35:27
|
||||
|
|
||||
LL | declval::<[u8; 10]>().as_ptr();
|
||||
| --------------------- ^^^^^^ this pointer will immediately be invalid
|
||||
| --------------------- ^^^^^^ pointer created here
|
||||
| |
|
||||
| this `[u8; 10]` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
|
||||
| this `[u8; 10]` is dropped at end of statement
|
||||
|
|
||||
= note: pointers do not have a lifetime; when calling `as_ptr` the `[u8; 10]` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned
|
||||
= help: you must make sure that the variable you bind the `[u8; 10]` to lives at least as long as the pointer returned by the call to `as_ptr`
|
||||
= help: in particular, if this pointer is returned from the current function, binding the `[u8; 10]` inside the function will not suffice
|
||||
= help: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
= help: bind the `[u8; 10]` to a variable such that it outlives the pointer returned by `as_ptr`
|
||||
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
|
||||
= note: returning a pointer to a local variable will always result in a dangling pointer
|
||||
= note: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
|
||||
error: a dangling pointer will be produced because the temporary `Box<[u8; 10]>` will be dropped
|
||||
error: this creates a dangling pointer because temporary `Box<[u8; 10]>` is dropped at end of statement
|
||||
--> $DIR/types.rs:37:32
|
||||
|
|
||||
LL | declval::<Box<[u8; 10]>>().as_ptr();
|
||||
| -------------------------- ^^^^^^ this pointer will immediately be invalid
|
||||
| -------------------------- ^^^^^^ pointer created here
|
||||
| |
|
||||
| this `Box<[u8; 10]>` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
|
||||
| this `Box<[u8; 10]>` is dropped at end of statement
|
||||
|
|
||||
= note: pointers do not have a lifetime; when calling `as_ptr` the `Box<[u8; 10]>` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned
|
||||
= help: you must make sure that the variable you bind the `Box<[u8; 10]>` to lives at least as long as the pointer returned by the call to `as_ptr`
|
||||
= help: in particular, if this pointer is returned from the current function, binding the `Box<[u8; 10]>` inside the function will not suffice
|
||||
= help: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
= help: bind the `Box<[u8; 10]>` to a variable such that it outlives the pointer returned by `as_ptr`
|
||||
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
|
||||
= note: returning a pointer to a local variable will always result in a dangling pointer
|
||||
= note: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
|
||||
error: a dangling pointer will be produced because the temporary `Box<Vec<u8>>` will be dropped
|
||||
error: this creates a dangling pointer because temporary `Box<Vec<u8>>` is dropped at end of statement
|
||||
--> $DIR/types.rs:39:31
|
||||
|
|
||||
LL | declval::<Box<Vec<u8>>>().as_ptr();
|
||||
| ------------------------- ^^^^^^ this pointer will immediately be invalid
|
||||
| ------------------------- ^^^^^^ pointer created here
|
||||
| |
|
||||
| this `Box<Vec<u8>>` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
|
||||
| this `Box<Vec<u8>>` is dropped at end of statement
|
||||
|
|
||||
= note: pointers do not have a lifetime; when calling `as_ptr` the `Box<Vec<u8>>` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned
|
||||
= help: you must make sure that the variable you bind the `Box<Vec<u8>>` to lives at least as long as the pointer returned by the call to `as_ptr`
|
||||
= help: in particular, if this pointer is returned from the current function, binding the `Box<Vec<u8>>` inside the function will not suffice
|
||||
= help: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
= help: bind the `Box<Vec<u8>>` to a variable such that it outlives the pointer returned by `as_ptr`
|
||||
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
|
||||
= note: returning a pointer to a local variable will always result in a dangling pointer
|
||||
= note: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
|
||||
error: a dangling pointer will be produced because the temporary `Box<String>` will be dropped
|
||||
error: this creates a dangling pointer because temporary `Box<String>` is dropped at end of statement
|
||||
--> $DIR/types.rs:41:30
|
||||
|
|
||||
LL | declval::<Box<String>>().as_ptr();
|
||||
| ------------------------ ^^^^^^ this pointer will immediately be invalid
|
||||
| ------------------------ ^^^^^^ pointer created here
|
||||
| |
|
||||
| this `Box<String>` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
|
||||
| this `Box<String>` is dropped at end of statement
|
||||
|
|
||||
= note: pointers do not have a lifetime; when calling `as_ptr` the `Box<String>` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned
|
||||
= help: you must make sure that the variable you bind the `Box<String>` to lives at least as long as the pointer returned by the call to `as_ptr`
|
||||
= help: in particular, if this pointer is returned from the current function, binding the `Box<String>` inside the function will not suffice
|
||||
= help: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
= help: bind the `Box<String>` to a variable such that it outlives the pointer returned by `as_ptr`
|
||||
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
|
||||
= note: returning a pointer to a local variable will always result in a dangling pointer
|
||||
= note: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
|
||||
error: a dangling pointer will be produced because the temporary `Box<Box<Box<Box<[u8]>>>>` will be dropped
|
||||
error: this creates a dangling pointer because temporary `Box<Box<Box<Box<[u8]>>>>` is dropped at end of statement
|
||||
--> $DIR/types.rs:43:43
|
||||
|
|
||||
LL | declval::<Box<Box<Box<Box<[u8]>>>>>().as_ptr();
|
||||
| ------------------------------------- ^^^^^^ this pointer will immediately be invalid
|
||||
| ------------------------------------- ^^^^^^ pointer created here
|
||||
| |
|
||||
| this `Box<Box<Box<Box<[u8]>>>>` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
|
||||
| this `Box<Box<Box<Box<[u8]>>>>` is dropped at end of statement
|
||||
|
|
||||
= note: pointers do not have a lifetime; when calling `as_ptr` the `Box<Box<Box<Box<[u8]>>>>` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned
|
||||
= help: you must make sure that the variable you bind the `Box<Box<Box<Box<[u8]>>>>` to lives at least as long as the pointer returned by the call to `as_ptr`
|
||||
= help: in particular, if this pointer is returned from the current function, binding the `Box<Box<Box<Box<[u8]>>>>` inside the function will not suffice
|
||||
= help: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
= help: bind the `Box<Box<Box<Box<[u8]>>>>` to a variable such that it outlives the pointer returned by `as_ptr`
|
||||
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
|
||||
= note: returning a pointer to a local variable will always result in a dangling pointer
|
||||
= note: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
|
||||
error: a dangling pointer will be produced because the temporary `Cell<u8>` will be dropped
|
||||
error: this creates a dangling pointer because temporary `Cell<u8>` is dropped at end of statement
|
||||
--> $DIR/types.rs:45:27
|
||||
|
|
||||
LL | declval::<Cell<u8>>().as_ptr();
|
||||
| --------------------- ^^^^^^ this pointer will immediately be invalid
|
||||
| --------------------- ^^^^^^ pointer created here
|
||||
| |
|
||||
| this `Cell<u8>` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
|
||||
| this `Cell<u8>` is dropped at end of statement
|
||||
|
|
||||
= note: pointers do not have a lifetime; when calling `as_ptr` the `Cell<u8>` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned
|
||||
= help: you must make sure that the variable you bind the `Cell<u8>` to lives at least as long as the pointer returned by the call to `as_ptr`
|
||||
= help: in particular, if this pointer is returned from the current function, binding the `Cell<u8>` inside the function will not suffice
|
||||
= help: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
= help: bind the `Cell<u8>` to a variable such that it outlives the pointer returned by `as_ptr`
|
||||
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
|
||||
= note: returning a pointer to a local variable will always result in a dangling pointer
|
||||
= note: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
|
||||
error: a dangling pointer will be produced because the temporary `MaybeUninit<u8>` will be dropped
|
||||
error: this creates a dangling pointer because temporary `MaybeUninit<u8>` is dropped at end of statement
|
||||
--> $DIR/types.rs:47:34
|
||||
|
|
||||
LL | declval::<MaybeUninit<u8>>().as_ptr();
|
||||
| ---------------------------- ^^^^^^ this pointer will immediately be invalid
|
||||
| ---------------------------- ^^^^^^ pointer created here
|
||||
| |
|
||||
| this `MaybeUninit<u8>` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
|
||||
| this `MaybeUninit<u8>` is dropped at end of statement
|
||||
|
|
||||
= note: pointers do not have a lifetime; when calling `as_ptr` the `MaybeUninit<u8>` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned
|
||||
= help: you must make sure that the variable you bind the `MaybeUninit<u8>` to lives at least as long as the pointer returned by the call to `as_ptr`
|
||||
= help: in particular, if this pointer is returned from the current function, binding the `MaybeUninit<u8>` inside the function will not suffice
|
||||
= help: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
= help: bind the `MaybeUninit<u8>` to a variable such that it outlives the pointer returned by `as_ptr`
|
||||
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
|
||||
= note: returning a pointer to a local variable will always result in a dangling pointer
|
||||
= note: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
|
||||
error: a dangling pointer will be produced because the temporary `Vec<AsPtrFake>` will be dropped
|
||||
error: this creates a dangling pointer because temporary `Vec<AsPtrFake>` is dropped at end of statement
|
||||
--> $DIR/types.rs:49:33
|
||||
|
|
||||
LL | declval::<Vec<AsPtrFake>>().as_ptr();
|
||||
| --------------------------- ^^^^^^ this pointer will immediately be invalid
|
||||
| --------------------------- ^^^^^^ pointer created here
|
||||
| |
|
||||
| this `Vec<AsPtrFake>` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
|
||||
| this `Vec<AsPtrFake>` is dropped at end of statement
|
||||
|
|
||||
= note: pointers do not have a lifetime; when calling `as_ptr` the `Vec<AsPtrFake>` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned
|
||||
= help: you must make sure that the variable you bind the `Vec<AsPtrFake>` to lives at least as long as the pointer returned by the call to `as_ptr`
|
||||
= help: in particular, if this pointer is returned from the current function, binding the `Vec<AsPtrFake>` inside the function will not suffice
|
||||
= help: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
= help: bind the `Vec<AsPtrFake>` to a variable such that it outlives the pointer returned by `as_ptr`
|
||||
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
|
||||
= note: returning a pointer to a local variable will always result in a dangling pointer
|
||||
= note: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
|
||||
error: a dangling pointer will be produced because the temporary `UnsafeCell<u8>` will be dropped
|
||||
error: this creates a dangling pointer because temporary `UnsafeCell<u8>` is dropped at end of statement
|
||||
--> $DIR/types.rs:51:33
|
||||
|
|
||||
LL | declval::<UnsafeCell<u8>>().get();
|
||||
| --------------------------- ^^^ this pointer will immediately be invalid
|
||||
| --------------------------- ^^^ pointer created here
|
||||
| |
|
||||
| this `UnsafeCell<u8>` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
|
||||
| this `UnsafeCell<u8>` is dropped at end of statement
|
||||
|
|
||||
= note: pointers do not have a lifetime; when calling `get` the `UnsafeCell<u8>` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned
|
||||
= help: you must make sure that the variable you bind the `UnsafeCell<u8>` to lives at least as long as the pointer returned by the call to `get`
|
||||
= help: in particular, if this pointer is returned from the current function, binding the `UnsafeCell<u8>` inside the function will not suffice
|
||||
= help: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
= help: bind the `UnsafeCell<u8>` to a variable such that it outlives the pointer returned by `get`
|
||||
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
|
||||
= note: returning a pointer to a local variable will always result in a dangling pointer
|
||||
= note: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
|
||||
error: a dangling pointer will be produced because the temporary `SyncUnsafeCell<u8>` will be dropped
|
||||
error: this creates a dangling pointer because temporary `SyncUnsafeCell<u8>` is dropped at end of statement
|
||||
--> $DIR/types.rs:53:37
|
||||
|
|
||||
LL | declval::<SyncUnsafeCell<u8>>().get();
|
||||
| ------------------------------- ^^^ this pointer will immediately be invalid
|
||||
| ------------------------------- ^^^ pointer created here
|
||||
| |
|
||||
| this `SyncUnsafeCell<u8>` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
|
||||
| this `SyncUnsafeCell<u8>` is dropped at end of statement
|
||||
|
|
||||
= note: pointers do not have a lifetime; when calling `get` the `SyncUnsafeCell<u8>` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned
|
||||
= help: you must make sure that the variable you bind the `SyncUnsafeCell<u8>` to lives at least as long as the pointer returned by the call to `get`
|
||||
= help: in particular, if this pointer is returned from the current function, binding the `SyncUnsafeCell<u8>` inside the function will not suffice
|
||||
= help: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
= help: bind the `SyncUnsafeCell<u8>` to a variable such that it outlives the pointer returned by `get`
|
||||
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
|
||||
= note: returning a pointer to a local variable will always result in a dangling pointer
|
||||
= note: for more information, see <https://doc.rust-lang.org/reference/destructors.html>
|
||||
|
||||
error: aborting due to 17 previous errors
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue