1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
|
warning: a dangling pointer will be produced because the local variable `x` will be dropped
--> $DIR/dangling-pointers-from-locals.rs:10:5
|
LL | fn simple() -> *const u8 {
| --------- return type of the function is `*const u8`
LL | let x = 0;
| - `x` is part the function and will be dropped at the end of the function
LL | &x
| ^^
|
= note: pointers do not have a lifetime; after returning, the `u8` will be deallocated at the end of the function because nothing is referencing it as far as the type system is concerned
= note: `#[warn(dangling_pointers_from_locals)]` on by default
warning: a dangling pointer will be produced because the local variable `x` will be dropped
--> $DIR/dangling-pointers-from-locals.rs:17:5
|
LL | fn bindings() -> *const u8 {
| --------- return type of the function is `*const u8`
LL | let x = 0;
| - `x` is part the function and will be dropped at the end of the function
LL | let x = &x;
| -- dangling pointer created here
LL | x
| ^
|
= note: pointers do not have a lifetime; after returning, the `u8` will be deallocated at the end of the function because nothing is referencing it as far as the type system is concerned
warning: a dangling pointer will be produced because the local variable `x` will be dropped
--> $DIR/dangling-pointers-from-locals.rs:24:12
|
LL | fn bindings_with_return() -> *const u8 {
| --------- return type of the function is `*const u8`
LL | let x = 42;
| - `x` is part the function and will be dropped at the end of the function
LL | let y = &x;
| -- dangling pointer created here
LL | return y;
| ^
|
= note: pointers do not have a lifetime; after returning, the `u8` will be deallocated at the end of the function because nothing is referencing it as far as the type system is concerned
warning: a dangling pointer will be produced because the local variable `x` will be dropped
--> $DIR/dangling-pointers-from-locals.rs:30:5
|
LL | fn with_simple_cast() -> *const u8 {
| --------- return type of the function is `*const u8`
LL | let x = 0u8;
| - `x` is part the function and will be dropped at the end of the function
LL | &x as *const u8
| --^^^^^^^^^^^^^
| |
| dangling pointer created here
|
= note: pointers do not have a lifetime; after returning, the `u8` will be deallocated at the end of the function because nothing is referencing it as far as the type system is concerned
warning: a dangling pointer will be produced because the local variable `x` will be dropped
--> $DIR/dangling-pointers-from-locals.rs:37:5
|
LL | fn bindings_and_casts() -> *const u8 {
| --------- return type of the function is `*const u8`
LL | let x = 0u8;
| - `x` is part the function and will be dropped at the end of the function
LL | let x = &x as *const u8;
| -- dangling pointer created here
LL | x as *const u8
| ^^^^^^^^^^^^^^
|
= note: pointers do not have a lifetime; after returning, the `u8` will be deallocated at the end of the function because nothing is referencing it as far as the type system is concerned
warning: a dangling pointer will be produced because the local variable `x` will be dropped
--> $DIR/dangling-pointers-from-locals.rs:43:12
|
LL | fn return_with_complex_cast() -> *mut u8 {
| ------- return type of the function is `*mut u8`
LL | let mut x = 0u8;
| ----- `x` is part the function and will be 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: pointers do not have a lifetime; after returning, the `u8` will be deallocated at the end of the function because nothing is referencing it as far as the type system is concerned
warning: a dangling pointer will be produced because the local variable `x` will be dropped
--> $DIR/dangling-pointers-from-locals.rs:49:5
|
LL | fn with_block() -> *const u8 {
| --------- return type of the function is `*const u8`
LL | let x = 0;
| - `x` is part the function and will be dropped at the end of the function
LL | &{ x }
| ^^^^^^
|
= note: pointers do not have a lifetime; after returning, the `u8` will be deallocated at the end of the function because nothing is referencing it as far as the type system is concerned
warning: a dangling pointer will be produced because the local variable `x` will be dropped
--> $DIR/dangling-pointers-from-locals.rs:57:13
|
LL | fn with_many_blocks() -> *const u8 {
| --------- return type of the function is `*const u8`
LL | let x = 0;
| - `x` is part the function and will be dropped at the end of the function
...
LL | / &{
LL | |
LL | | { x }
LL | | }
| |_____________^
|
= note: pointers do not have a lifetime; after returning, the `u8` will be deallocated at the end of the function because nothing is referencing it as far as the type system is concerned
warning: a dangling pointer will be produced because the local variable `x` will be dropped
--> $DIR/dangling-pointers-from-locals.rs:67:12
|
LL | fn simple_return() -> *const u8 {
| --------- return type of the function is `*const u8`
LL | let x = 0;
| - `x` is part the function and will be dropped at the end of the function
LL | return &x;
| ^^
|
= note: pointers do not have a lifetime; after returning, the `u8` will be deallocated at the end of the function because nothing is referencing it as far as the type system is concerned
warning: a dangling pointer will be produced because the local variable `x` will be dropped
--> $DIR/dangling-pointers-from-locals.rs:73:12
|
LL | fn return_mut() -> *mut u8 {
| ------- return type of the function is `*mut u8`
LL | let mut x = 0;
| ----- `x` is part the function and will be dropped at the end of the function
LL | return &mut x;
| ^^^^^^
|
= note: pointers do not have a lifetime; after returning, the `u8` will be deallocated at the end of the function because nothing is referencing it as far as the type system is concerned
warning: a dangling pointer will be produced because the local variable `x` will be dropped
--> $DIR/dangling-pointers-from-locals.rs:80:16
|
LL | fn const_and_flow() -> *const u8 {
| --------- return type of the function is `*const u8`
LL | if false {
LL | let x = 8;
| - `x` is part the function and will be dropped at the end of the function
LL | return &x;
| ^^
|
= note: pointers do not have a lifetime; after returning, the `u8` will be deallocated at the end of the function because nothing is referencing it as far as the type system is concerned
warning: a dangling pointer will be produced because the local variable `x` will be dropped
--> $DIR/dangling-pointers-from-locals.rs:88:5
|
LL | fn vector<T: Default>() -> *const Vec<T> {
| ------------- return type of the function is `*const Vec<T>`
LL | let x = vec![T::default()];
| - `x` is part the function and will be dropped at the end of the function
LL | &x
| ^^
|
= note: pointers do not have a lifetime; after returning, the `Vec<T>` will be deallocated at the end of the function because nothing is referencing it as far as the type system is concerned
warning: a dangling pointer will be produced because the local variable `x` will be dropped
--> $DIR/dangling-pointers-from-locals.rs:94:12
|
LL | fn local_adt() -> *const Adt {
| ---------- return type of the function is `*const Adt`
LL | let x = Adt(5);
| - `x` is part the function and will be dropped at the end of the function
LL | return &x;
| ^^
|
= note: pointers do not have a lifetime; after returning, the `Adt` will be deallocated at the end of the function because nothing is referencing it as far as the type system is concerned
warning: a dangling pointer will be produced because the local variable `x` will be dropped
--> $DIR/dangling-pointers-from-locals.rs:101:16
|
LL | let _x = || -> *const u8 {
| --------- return type of the closure is `*const u8`
LL | let x = 8;
| - `x` is part the closure and will be dropped at the end of the closure
LL | return &x;
| ^^
|
= note: pointers do not have a lifetime; after returning, the `u8` will be deallocated at the end of the closure because nothing is referencing it as far as the type system is concerned
warning: a dangling pointer will be produced because the local variable `x` will be dropped
--> $DIR/dangling-pointers-from-locals.rs:113:5
|
LL | fn fn_ptr() -> *const fn() -> u8 {
| ----------------- return type of the function is `*const fn() -> u8`
...
LL | let x = ret_u8 as fn() -> u8;
| - `x` is part the function and will be dropped at the end of the function
LL | &x
| ^^
|
= note: pointers do not have a lifetime; after returning, the `fn() -> u8` will be deallocated at the end of the function because nothing is referencing it as far as the type system is concerned
warning: a dangling pointer will be produced because the local variable `a` will be dropped
--> $DIR/dangling-pointers-from-locals.rs:118:5
|
LL | fn as_arg(a: Adt) -> *const Adt {
| - ---------- return type of the function is `*const Adt`
| |
| `a` is part the function and will be dropped at the end of the function
LL | &a
| ^^
|
= note: pointers do not have a lifetime; after returning, the `Adt` will be deallocated at the end of the function because nothing is referencing it as far as the type system is concerned
warning: a dangling pointer will be produced because the local variable `a` will be dropped
--> $DIR/dangling-pointers-from-locals.rs:123:5
|
LL | fn fn_ptr_as_arg(a: fn() -> u8) -> *const fn() -> u8 {
| - ----------------- return type of the function is `*const fn() -> u8`
| |
| `a` is part the function and will be dropped at the end of the function
LL | &a
| ^^
|
= note: pointers do not have a lifetime; after returning, the `fn() -> u8` will be deallocated at the end of the function because nothing is referencing it as far as the type system is concerned
warning: a dangling pointer will be produced because the local variable `a` will be dropped
--> $DIR/dangling-pointers-from-locals.rs:128:5
|
LL | fn ptr_as_arg(a: *const Adt) -> *const *const Adt {
| - ----------------- return type of the function is `*const *const Adt`
| |
| `a` is part the function and will be dropped at the end of the function
LL | &a
| ^^
|
= note: pointers do not have a lifetime; after returning, the `*const Adt` will be deallocated at the end of the function because nothing is referencing it as far as the type system is concerned
warning: a dangling pointer will be produced because the local variable `a` will be dropped
--> $DIR/dangling-pointers-from-locals.rs:133:5
|
LL | fn adt_as_arg(a: &Adt) -> *const &Adt {
| - ----------- return type of the function is `*const &Adt`
| |
| `a` is part the function and will be dropped at the end of the function
LL | &a
| ^^
|
= note: pointers do not have a lifetime; after returning, the `&Adt` will be deallocated at the end of the function because nothing is referencing it as far as the type system is concerned
warning: 19 warnings emitted
|