blob: 45acc74ac34e5fdf8d5a48a8c8ec3abbf2a81abd [file] [log] [blame] [edit]
warning: function returns a dangling pointer to dropped local variable `x`
--> $DIR/dangling-pointers-from-locals.rs:10:5
|
LL | fn simple() -> *const u8 {
| --------- return type is `*const u8`
LL | let x = 0;
| - local variable `x` is dropped at the end of the function
LL | &x
| ^^
|
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
= note: `#[warn(dangling_pointers_from_locals)]` on by default
warning: function returns a dangling pointer to dropped local variable `x`
--> $DIR/dangling-pointers-from-locals.rs:17:5
|
LL | fn bindings() -> *const u8 {
| --------- return type is `*const u8`
LL | let x = 0;
| - local variable `x` is dropped at the end of the function
LL | let x = &x;
| -- dangling pointer created here
LL | x
| ^
|
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
warning: function returns a dangling pointer to dropped local variable `x`
--> $DIR/dangling-pointers-from-locals.rs:24:12
|
LL | fn bindings_with_return() -> *const u8 {
| --------- return type is `*const u8`
LL | let x = 42;
| - local variable `x` is dropped at the end of the function
LL | let y = &x;
| -- dangling pointer created here
LL | return y;
| ^
|
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
warning: function returns a dangling pointer to dropped local variable `x`
--> $DIR/dangling-pointers-from-locals.rs:30:5
|
LL | fn with_simple_cast() -> *const u8 {
| --------- return type is `*const u8`
LL | let x = 0u8;
| - local variable `x` is dropped at the end of the function
LL | &x as *const u8
| --^^^^^^^^^^^^^
| |
| dangling pointer created here
|
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
warning: function returns a dangling pointer to dropped local variable `x`
--> $DIR/dangling-pointers-from-locals.rs:37:5
|
LL | fn bindings_and_casts() -> *const u8 {
| --------- return type is `*const u8`
LL | let x = 0u8;
| - local variable `x` is dropped at the end of the function
LL | let x = &x as *const u8;
| -- dangling pointer created here
LL | x as *const u8
| ^^^^^^^^^^^^^^
|
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
warning: function returns a dangling pointer to dropped local variable `x`
--> $DIR/dangling-pointers-from-locals.rs:43:12
|
LL | fn return_with_complex_cast() -> *mut u8 {
| ------- return type is `*mut u8`
LL | let mut x = 0u8;
| ----- local variable `x` is dropped at the end of the function
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
warning: function returns a dangling pointer to dropped local variable `x`
--> $DIR/dangling-pointers-from-locals.rs:49:5
|
LL | fn with_block() -> *const u8 {
| --------- return type is `*const u8`
LL | let x = 0;
| - local variable `x` is dropped at the end of the function
LL | &{ x }
| ^^^^^^
|
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
warning: function returns a dangling pointer to dropped local variable `x`
--> $DIR/dangling-pointers-from-locals.rs:57:13
|
LL | fn with_many_blocks() -> *const u8 {
| --------- return type is `*const u8`
LL | let x = 0;
| - local variable `x` is dropped at the end of the function
...
LL | / &{
LL | |
LL | | { x }
LL | | }
| |_____________^
|
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
warning: function returns a dangling pointer to dropped local variable `x`
--> $DIR/dangling-pointers-from-locals.rs:67:12
|
LL | fn simple_return() -> *const u8 {
| --------- return type is `*const u8`
LL | let x = 0;
| - local variable `x` is dropped at the end of the function
LL | return &x;
| ^^
|
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
warning: function returns a dangling pointer to dropped local variable `x`
--> $DIR/dangling-pointers-from-locals.rs:73:12
|
LL | fn return_mut() -> *mut u8 {
| ------- return type is `*mut u8`
LL | let mut x = 0;
| ----- local variable `x` is dropped at the end of the function
LL | return &mut x;
| ^^^^^^
|
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
warning: function returns a dangling pointer to dropped local variable `x`
--> $DIR/dangling-pointers-from-locals.rs:80:16
|
LL | fn const_and_flow() -> *const u8 {
| --------- return type is `*const u8`
LL | if false {
LL | let x = 8;
| - local variable `x` is dropped at the end of the function
LL | return &x;
| ^^
|
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
warning: function returns a dangling pointer to dropped local variable `x`
--> $DIR/dangling-pointers-from-locals.rs:88:5
|
LL | fn vector<T: Default>() -> *const Vec<T> {
| ------------- return type is `*const Vec<T>`
LL | let x = vec![T::default()];
| - local variable `x` is dropped at the end of the function
LL | &x
| ^^
|
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
warning: function returns a dangling pointer to dropped local variable `x`
--> $DIR/dangling-pointers-from-locals.rs:94:12
|
LL | fn local_adt() -> *const Adt {
| ---------- return type is `*const Adt`
LL | let x = Adt(5);
| - local variable `x` is dropped at the end of the function
LL | return &x;
| ^^
|
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
warning: closure returns a dangling pointer to dropped local variable `x`
--> $DIR/dangling-pointers-from-locals.rs:101:16
|
LL | let _x = || -> *const u8 {
| --------- return type is `*const u8`
LL | let x = 8;
| - local variable `x` is dropped at the end of the closure
LL | return &x;
| ^^
|
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
warning: function returns a dangling pointer to dropped local variable `x`
--> $DIR/dangling-pointers-from-locals.rs:113:5
|
LL | fn fn_ptr() -> *const fn() -> u8 {
| ----------------- return type is `*const fn() -> u8`
...
LL | let x = ret_u8 as fn() -> u8;
| - local variable `x` is dropped at the end of the function
LL | &x
| ^^
|
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
warning: function returns a dangling pointer to dropped local variable `a`
--> $DIR/dangling-pointers-from-locals.rs:118:5
|
LL | fn as_arg(a: Adt) -> *const Adt {
| - ---------- return type is `*const Adt`
| |
| local variable `a` is dropped at the end of the function
LL | &a
| ^^
|
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
warning: function returns a dangling pointer to dropped local variable `a`
--> $DIR/dangling-pointers-from-locals.rs:123:5
|
LL | fn fn_ptr_as_arg(a: fn() -> u8) -> *const fn() -> u8 {
| - ----------------- return type is `*const fn() -> u8`
| |
| local variable `a` is dropped at the end of the function
LL | &a
| ^^
|
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
warning: function returns a dangling pointer to dropped local variable `a`
--> $DIR/dangling-pointers-from-locals.rs:128:5
|
LL | fn ptr_as_arg(a: *const Adt) -> *const *const Adt {
| - ----------------- return type is `*const *const Adt`
| |
| local variable `a` is dropped at the end of the function
LL | &a
| ^^
|
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
warning: function returns a dangling pointer to dropped local variable `a`
--> $DIR/dangling-pointers-from-locals.rs:133:5
|
LL | fn adt_as_arg(a: &Adt) -> *const &Adt {
| - ----------- return type is `*const &Adt`
| |
| local variable `a` is dropped at the end of the function
LL | &a
| ^^
|
= note: a dangling pointer is safe, but dereferencing one is undefined behavior
warning: 19 warnings emitted