Skip to content

Commit 3288be5

Browse files
committed
test in a way that works even with musl
1 parent 72d9fe8 commit 3288be5

File tree

2 files changed

+58
-65
lines changed

2 files changed

+58
-65
lines changed

src/test/ui/lint/uninitialized-zeroed.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#![deny(invalid_value)]
88

99
use std::mem::{self, MaybeUninit};
10+
use std::ptr::NonNull;
1011
use std::num::NonZeroU32;
1112

1213
enum Void {}
@@ -63,8 +64,8 @@ fn main() {
6364
let _val: Wrap<(RefPair, i32)> = mem::zeroed(); //~ ERROR: does not permit zero-initialization
6465
let _val: Wrap<(RefPair, i32)> = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized
6566

66-
let _val: Vec<i32> = mem::zeroed(); //~ ERROR: does not permit zero-initialization
67-
let _val: Vec<i32> = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized
67+
let _val: NonNull<i32> = mem::zeroed(); //~ ERROR: does not permit zero-initialization
68+
let _val: NonNull<i32> = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized
6869

6970
// Things that can be zero, but not uninit.
7071
let _val: bool = mem::zeroed();

src/test/ui/lint/uninitialized-zeroed.stderr

+55-63
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: the type `&'static T` does not permit zero-initialization
2-
--> $DIR/uninitialized-zeroed.rs:28:32
2+
--> $DIR/uninitialized-zeroed.rs:29:32
33
|
44
LL | let _val: &'static T = mem::zeroed();
55
| ^^^^^^^^^^^^^
@@ -15,7 +15,7 @@ LL | #![deny(invalid_value)]
1515
= note: References must be non-null
1616

1717
error: the type `&'static T` does not permit being left uninitialized
18-
--> $DIR/uninitialized-zeroed.rs:29:32
18+
--> $DIR/uninitialized-zeroed.rs:30:32
1919
|
2020
LL | let _val: &'static T = mem::uninitialized();
2121
| ^^^^^^^^^^^^^^^^^^^^
@@ -26,7 +26,7 @@ LL | let _val: &'static T = mem::uninitialized();
2626
= note: References must be non-null
2727

2828
error: the type `Wrap<&'static T>` does not permit zero-initialization
29-
--> $DIR/uninitialized-zeroed.rs:31:38
29+
--> $DIR/uninitialized-zeroed.rs:32:38
3030
|
3131
LL | let _val: Wrap<&'static T> = mem::zeroed();
3232
| ^^^^^^^^^^^^^
@@ -35,13 +35,13 @@ LL | let _val: Wrap<&'static T> = mem::zeroed();
3535
| help: use `MaybeUninit<T>` instead
3636
|
3737
note: References must be non-null (in this struct field)
38-
--> $DIR/uninitialized-zeroed.rs:17:18
38+
--> $DIR/uninitialized-zeroed.rs:18:18
3939
|
4040
LL | struct Wrap<T> { wrapped: T }
4141
| ^^^^^^^^^^
4242

4343
error: the type `Wrap<&'static T>` does not permit being left uninitialized
44-
--> $DIR/uninitialized-zeroed.rs:32:38
44+
--> $DIR/uninitialized-zeroed.rs:33:38
4545
|
4646
LL | let _val: Wrap<&'static T> = mem::uninitialized();
4747
| ^^^^^^^^^^^^^^^^^^^^
@@ -50,13 +50,13 @@ LL | let _val: Wrap<&'static T> = mem::uninitialized();
5050
| help: use `MaybeUninit<T>` instead
5151
|
5252
note: References must be non-null (in this struct field)
53-
--> $DIR/uninitialized-zeroed.rs:17:18
53+
--> $DIR/uninitialized-zeroed.rs:18:18
5454
|
5555
LL | struct Wrap<T> { wrapped: T }
5656
| ^^^^^^^^^^
5757

5858
error: the type `!` does not permit zero-initialization
59-
--> $DIR/uninitialized-zeroed.rs:39:23
59+
--> $DIR/uninitialized-zeroed.rs:40:23
6060
|
6161
LL | let _val: ! = mem::zeroed();
6262
| ^^^^^^^^^^^^^
@@ -67,7 +67,7 @@ LL | let _val: ! = mem::zeroed();
6767
= note: The never type (`!`) has no valid value
6868

6969
error: the type `!` does not permit being left uninitialized
70-
--> $DIR/uninitialized-zeroed.rs:40:23
70+
--> $DIR/uninitialized-zeroed.rs:41:23
7171
|
7272
LL | let _val: ! = mem::uninitialized();
7373
| ^^^^^^^^^^^^^^^^^^^^
@@ -78,7 +78,7 @@ LL | let _val: ! = mem::uninitialized();
7878
= note: The never type (`!`) has no valid value
7979

8080
error: the type `(i32, !)` does not permit zero-initialization
81-
--> $DIR/uninitialized-zeroed.rs:42:30
81+
--> $DIR/uninitialized-zeroed.rs:43:30
8282
|
8383
LL | let _val: (i32, !) = mem::zeroed();
8484
| ^^^^^^^^^^^^^
@@ -89,7 +89,7 @@ LL | let _val: (i32, !) = mem::zeroed();
8989
= note: The never type (`!`) has no valid value
9090

9191
error: the type `(i32, !)` does not permit being left uninitialized
92-
--> $DIR/uninitialized-zeroed.rs:43:30
92+
--> $DIR/uninitialized-zeroed.rs:44:30
9393
|
9494
LL | let _val: (i32, !) = mem::uninitialized();
9595
| ^^^^^^^^^^^^^^^^^^^^
@@ -100,7 +100,7 @@ LL | let _val: (i32, !) = mem::uninitialized();
100100
= note: The never type (`!`) has no valid value
101101

102102
error: the type `Void` does not permit zero-initialization
103-
--> $DIR/uninitialized-zeroed.rs:45:26
103+
--> $DIR/uninitialized-zeroed.rs:46:26
104104
|
105105
LL | let _val: Void = mem::zeroed();
106106
| ^^^^^^^^^^^^^
@@ -111,7 +111,7 @@ LL | let _val: Void = mem::zeroed();
111111
= note: 0-variant enums have no valid value
112112

113113
error: the type `Void` does not permit being left uninitialized
114-
--> $DIR/uninitialized-zeroed.rs:46:26
114+
--> $DIR/uninitialized-zeroed.rs:47:26
115115
|
116116
LL | let _val: Void = mem::uninitialized();
117117
| ^^^^^^^^^^^^^^^^^^^^
@@ -122,7 +122,7 @@ LL | let _val: Void = mem::uninitialized();
122122
= note: 0-variant enums have no valid value
123123

124124
error: the type `&'static i32` does not permit zero-initialization
125-
--> $DIR/uninitialized-zeroed.rs:48:34
125+
--> $DIR/uninitialized-zeroed.rs:49:34
126126
|
127127
LL | let _val: &'static i32 = mem::zeroed();
128128
| ^^^^^^^^^^^^^
@@ -133,7 +133,7 @@ LL | let _val: &'static i32 = mem::zeroed();
133133
= note: References must be non-null
134134

135135
error: the type `&'static i32` does not permit being left uninitialized
136-
--> $DIR/uninitialized-zeroed.rs:49:34
136+
--> $DIR/uninitialized-zeroed.rs:50:34
137137
|
138138
LL | let _val: &'static i32 = mem::uninitialized();
139139
| ^^^^^^^^^^^^^^^^^^^^
@@ -144,7 +144,7 @@ LL | let _val: &'static i32 = mem::uninitialized();
144144
= note: References must be non-null
145145

146146
error: the type `Ref` does not permit zero-initialization
147-
--> $DIR/uninitialized-zeroed.rs:51:25
147+
--> $DIR/uninitialized-zeroed.rs:52:25
148148
|
149149
LL | let _val: Ref = mem::zeroed();
150150
| ^^^^^^^^^^^^^
@@ -153,13 +153,13 @@ LL | let _val: Ref = mem::zeroed();
153153
| help: use `MaybeUninit<T>` instead
154154
|
155155
note: References must be non-null (in this struct field)
156-
--> $DIR/uninitialized-zeroed.rs:14:12
156+
--> $DIR/uninitialized-zeroed.rs:15:12
157157
|
158158
LL | struct Ref(&'static i32);
159159
| ^^^^^^^^^^^^
160160

161161
error: the type `Ref` does not permit being left uninitialized
162-
--> $DIR/uninitialized-zeroed.rs:52:25
162+
--> $DIR/uninitialized-zeroed.rs:53:25
163163
|
164164
LL | let _val: Ref = mem::uninitialized();
165165
| ^^^^^^^^^^^^^^^^^^^^
@@ -168,13 +168,13 @@ LL | let _val: Ref = mem::uninitialized();
168168
| help: use `MaybeUninit<T>` instead
169169
|
170170
note: References must be non-null (in this struct field)
171-
--> $DIR/uninitialized-zeroed.rs:14:12
171+
--> $DIR/uninitialized-zeroed.rs:15:12
172172
|
173173
LL | struct Ref(&'static i32);
174174
| ^^^^^^^^^^^^
175175

176176
error: the type `fn()` does not permit zero-initialization
177-
--> $DIR/uninitialized-zeroed.rs:54:26
177+
--> $DIR/uninitialized-zeroed.rs:55:26
178178
|
179179
LL | let _val: fn() = mem::zeroed();
180180
| ^^^^^^^^^^^^^
@@ -185,7 +185,7 @@ LL | let _val: fn() = mem::zeroed();
185185
= note: Function pointers must be non-null
186186

187187
error: the type `fn()` does not permit being left uninitialized
188-
--> $DIR/uninitialized-zeroed.rs:55:26
188+
--> $DIR/uninitialized-zeroed.rs:56:26
189189
|
190190
LL | let _val: fn() = mem::uninitialized();
191191
| ^^^^^^^^^^^^^^^^^^^^
@@ -196,7 +196,7 @@ LL | let _val: fn() = mem::uninitialized();
196196
= note: Function pointers must be non-null
197197

198198
error: the type `Wrap<fn()>` does not permit zero-initialization
199-
--> $DIR/uninitialized-zeroed.rs:57:32
199+
--> $DIR/uninitialized-zeroed.rs:58:32
200200
|
201201
LL | let _val: Wrap<fn()> = mem::zeroed();
202202
| ^^^^^^^^^^^^^
@@ -205,13 +205,13 @@ LL | let _val: Wrap<fn()> = mem::zeroed();
205205
| help: use `MaybeUninit<T>` instead
206206
|
207207
note: Function pointers must be non-null (in this struct field)
208-
--> $DIR/uninitialized-zeroed.rs:17:18
208+
--> $DIR/uninitialized-zeroed.rs:18:18
209209
|
210210
LL | struct Wrap<T> { wrapped: T }
211211
| ^^^^^^^^^^
212212

213213
error: the type `Wrap<fn()>` does not permit being left uninitialized
214-
--> $DIR/uninitialized-zeroed.rs:58:32
214+
--> $DIR/uninitialized-zeroed.rs:59:32
215215
|
216216
LL | let _val: Wrap<fn()> = mem::uninitialized();
217217
| ^^^^^^^^^^^^^^^^^^^^
@@ -220,13 +220,13 @@ LL | let _val: Wrap<fn()> = mem::uninitialized();
220220
| help: use `MaybeUninit<T>` instead
221221
|
222222
note: Function pointers must be non-null (in this struct field)
223-
--> $DIR/uninitialized-zeroed.rs:17:18
223+
--> $DIR/uninitialized-zeroed.rs:18:18
224224
|
225225
LL | struct Wrap<T> { wrapped: T }
226226
| ^^^^^^^^^^
227227

228228
error: the type `WrapEnum<fn()>` does not permit zero-initialization
229-
--> $DIR/uninitialized-zeroed.rs:60:36
229+
--> $DIR/uninitialized-zeroed.rs:61:36
230230
|
231231
LL | let _val: WrapEnum<fn()> = mem::zeroed();
232232
| ^^^^^^^^^^^^^
@@ -235,13 +235,13 @@ LL | let _val: WrapEnum<fn()> = mem::zeroed();
235235
| help: use `MaybeUninit<T>` instead
236236
|
237237
note: Function pointers must be non-null (in this enum field)
238-
--> $DIR/uninitialized-zeroed.rs:18:28
238+
--> $DIR/uninitialized-zeroed.rs:19:28
239239
|
240240
LL | enum WrapEnum<T> { Wrapped(T) }
241241
| ^
242242

243243
error: the type `WrapEnum<fn()>` does not permit being left uninitialized
244-
--> $DIR/uninitialized-zeroed.rs:61:36
244+
--> $DIR/uninitialized-zeroed.rs:62:36
245245
|
246246
LL | let _val: WrapEnum<fn()> = mem::uninitialized();
247247
| ^^^^^^^^^^^^^^^^^^^^
@@ -250,13 +250,13 @@ LL | let _val: WrapEnum<fn()> = mem::uninitialized();
250250
| help: use `MaybeUninit<T>` instead
251251
|
252252
note: Function pointers must be non-null (in this enum field)
253-
--> $DIR/uninitialized-zeroed.rs:18:28
253+
--> $DIR/uninitialized-zeroed.rs:19:28
254254
|
255255
LL | enum WrapEnum<T> { Wrapped(T) }
256256
| ^
257257

258258
error: the type `Wrap<(RefPair, i32)>` does not permit zero-initialization
259-
--> $DIR/uninitialized-zeroed.rs:63:42
259+
--> $DIR/uninitialized-zeroed.rs:64:42
260260
|
261261
LL | let _val: Wrap<(RefPair, i32)> = mem::zeroed();
262262
| ^^^^^^^^^^^^^
@@ -265,13 +265,13 @@ LL | let _val: Wrap<(RefPair, i32)> = mem::zeroed();
265265
| help: use `MaybeUninit<T>` instead
266266
|
267267
note: References must be non-null (in this struct field)
268-
--> $DIR/uninitialized-zeroed.rs:15:16
268+
--> $DIR/uninitialized-zeroed.rs:16:16
269269
|
270270
LL | struct RefPair((&'static i32, i32));
271271
| ^^^^^^^^^^^^^^^^^^^
272272

273273
error: the type `Wrap<(RefPair, i32)>` does not permit being left uninitialized
274-
--> $DIR/uninitialized-zeroed.rs:64:42
274+
--> $DIR/uninitialized-zeroed.rs:65:42
275275
|
276276
LL | let _val: Wrap<(RefPair, i32)> = mem::uninitialized();
277277
| ^^^^^^^^^^^^^^^^^^^^
@@ -280,43 +280,35 @@ LL | let _val: Wrap<(RefPair, i32)> = mem::uninitialized();
280280
| help: use `MaybeUninit<T>` instead
281281
|
282282
note: References must be non-null (in this struct field)
283-
--> $DIR/uninitialized-zeroed.rs:15:16
283+
--> $DIR/uninitialized-zeroed.rs:16:16
284284
|
285285
LL | struct RefPair((&'static i32, i32));
286286
| ^^^^^^^^^^^^^^^^^^^
287287

288-
error: the type `std::vec::Vec<i32>` does not permit zero-initialization
289-
--> $DIR/uninitialized-zeroed.rs:66:30
290-
|
291-
LL | let _val: Vec<i32> = mem::zeroed();
292-
| ^^^^^^^^^^^^^
293-
| |
294-
| this code causes undefined behavior when executed
295-
| help: use `MaybeUninit<T>` instead
288+
error: the type `std::ptr::NonNull<i32>` does not permit zero-initialization
289+
--> $DIR/uninitialized-zeroed.rs:67:34
296290
|
297-
note: std::ptr::Unique<i32> must be non-null (in this struct field)
298-
--> $SRC_DIR/liballoc/raw_vec.rs:LL:COL
291+
LL | let _val: NonNull<i32> = mem::zeroed();
292+
| ^^^^^^^^^^^^^
293+
| |
294+
| this code causes undefined behavior when executed
295+
| help: use `MaybeUninit<T>` instead
299296
|
300-
LL | ptr: Unique<T>,
301-
| ^^^^^^^^^^^^^^
297+
= note: std::ptr::NonNull<i32> must be non-null
302298

303-
error: the type `std::vec::Vec<i32>` does not permit being left uninitialized
304-
--> $DIR/uninitialized-zeroed.rs:67:30
305-
|
306-
LL | let _val: Vec<i32> = mem::uninitialized();
307-
| ^^^^^^^^^^^^^^^^^^^^
308-
| |
309-
| this code causes undefined behavior when executed
310-
| help: use `MaybeUninit<T>` instead
299+
error: the type `std::ptr::NonNull<i32>` does not permit being left uninitialized
300+
--> $DIR/uninitialized-zeroed.rs:68:34
311301
|
312-
note: std::ptr::Unique<i32> must be non-null (in this struct field)
313-
--> $SRC_DIR/liballoc/raw_vec.rs:LL:COL
302+
LL | let _val: NonNull<i32> = mem::uninitialized();
303+
| ^^^^^^^^^^^^^^^^^^^^
304+
| |
305+
| this code causes undefined behavior when executed
306+
| help: use `MaybeUninit<T>` instead
314307
|
315-
LL | ptr: Unique<T>,
316-
| ^^^^^^^^^^^^^^
308+
= note: std::ptr::NonNull<i32> must be non-null
317309

318310
error: the type `bool` does not permit being left uninitialized
319-
--> $DIR/uninitialized-zeroed.rs:71:26
311+
--> $DIR/uninitialized-zeroed.rs:72:26
320312
|
321313
LL | let _val: bool = mem::uninitialized();
322314
| ^^^^^^^^^^^^^^^^^^^^
@@ -327,7 +319,7 @@ LL | let _val: bool = mem::uninitialized();
327319
= note: Booleans must be `true` or `false`
328320

329321
error: the type `Wrap<char>` does not permit being left uninitialized
330-
--> $DIR/uninitialized-zeroed.rs:74:32
322+
--> $DIR/uninitialized-zeroed.rs:75:32
331323
|
332324
LL | let _val: Wrap<char> = mem::uninitialized();
333325
| ^^^^^^^^^^^^^^^^^^^^
@@ -336,13 +328,13 @@ LL | let _val: Wrap<char> = mem::uninitialized();
336328
| help: use `MaybeUninit<T>` instead
337329
|
338330
note: Characters must be a valid unicode codepoint (in this struct field)
339-
--> $DIR/uninitialized-zeroed.rs:17:18
331+
--> $DIR/uninitialized-zeroed.rs:18:18
340332
|
341333
LL | struct Wrap<T> { wrapped: T }
342334
| ^^^^^^^^^^
343335

344336
error: the type `NonBig` does not permit being left uninitialized
345-
--> $DIR/uninitialized-zeroed.rs:77:28
337+
--> $DIR/uninitialized-zeroed.rs:78:28
346338
|
347339
LL | let _val: NonBig = mem::uninitialized();
348340
| ^^^^^^^^^^^^^^^^^^^^
@@ -353,7 +345,7 @@ LL | let _val: NonBig = mem::uninitialized();
353345
= note: NonBig must be initialized inside its custom valid range
354346

355347
error: the type `&'static i32` does not permit zero-initialization
356-
--> $DIR/uninitialized-zeroed.rs:80:34
348+
--> $DIR/uninitialized-zeroed.rs:81:34
357349
|
358350
LL | let _val: &'static i32 = mem::transmute(0usize);
359351
| ^^^^^^^^^^^^^^^^^^^^^^
@@ -364,7 +356,7 @@ LL | let _val: &'static i32 = mem::transmute(0usize);
364356
= note: References must be non-null
365357

366358
error: the type `&'static [i32]` does not permit zero-initialization
367-
--> $DIR/uninitialized-zeroed.rs:81:36
359+
--> $DIR/uninitialized-zeroed.rs:82:36
368360
|
369361
LL | let _val: &'static [i32] = mem::transmute((0usize, 0usize));
370362
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -375,7 +367,7 @@ LL | let _val: &'static [i32] = mem::transmute((0usize, 0usize));
375367
= note: References must be non-null
376368

377369
error: the type `std::num::NonZeroU32` does not permit zero-initialization
378-
--> $DIR/uninitialized-zeroed.rs:82:32
370+
--> $DIR/uninitialized-zeroed.rs:83:32
379371
|
380372
LL | let _val: NonZeroU32 = mem::transmute(0);
381373
| ^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)