Commit 4dea3a2
authored
Rollup merge of rust-lang#108000 - y21:no-zero-init-for-uninhabited, r=jackh726
lint: don't suggest MaybeUninit::assume_init for uninhabited types
Creating a zeroed uninhabited type such as `!` or an empty enum with `mem::zeroed()` (or transmuting `()` to `!`) currently triggers this lint:
```rs
warning: the type `!` does not permit zero-initialization
--> test.rs:5:23
|
5 | let _val: ! = mem::zeroed();
| ^^^^^^^^^^^^^
| |
| this code causes undefined behavior when executed
| help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
|
= note: the `!` type has no valid value
```
The `MaybeUninit` suggestion in the help message seems confusing/useless for uninhabited types, as such a type cannot be fully initialized in the first place (as the note implies).
This PR limits this help message to inhabited types which can be initializedFile tree
6 files changed
+32
-59
lines changed- compiler/rustc_lint/src
- tests/ui
- consts/const-eval
- lint
- statics
6 files changed
+32
-59
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2635 | 2635 | | |
2636 | 2636 | | |
2637 | 2637 | | |
2638 | | - | |
| 2638 | + | |
| 2639 | + | |
| 2640 | + | |
| 2641 | + | |
| 2642 | + | |
| 2643 | + | |
| 2644 | + | |
2639 | 2645 | | |
2640 | 2646 | | |
2641 | 2647 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
12 | 14 | | |
13 | 15 | | |
14 | 16 | | |
| |||
419 | 421 | | |
420 | 422 | | |
421 | 423 | | |
| 424 | + | |
422 | 425 | | |
423 | 426 | | |
424 | 427 | | |
| |||
428 | 431 | | |
429 | 432 | | |
430 | 433 | | |
431 | | - | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
432 | 441 | | |
433 | 442 | | |
434 | 443 | | |
| |||
Lines changed: 2 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
| 5 | + | |
9 | 6 | | |
10 | 7 | | |
11 | 8 | | |
| |||
40 | 37 | | |
41 | 38 | | |
42 | 39 | | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
| 40 | + | |
47 | 41 | | |
48 | 42 | | |
49 | 43 | | |
| |||
Lines changed: 2 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
| 5 | + | |
9 | 6 | | |
10 | 7 | | |
11 | 8 | | |
| |||
40 | 37 | | |
41 | 38 | | |
42 | 39 | | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
| 40 | + | |
47 | 41 | | |
48 | 42 | | |
49 | 43 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
| 64 | + | |
68 | 65 | | |
69 | 66 | | |
70 | 67 | | |
71 | 68 | | |
72 | 69 | | |
73 | 70 | | |
74 | 71 | | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
| 72 | + | |
79 | 73 | | |
80 | 74 | | |
81 | 75 | | |
82 | 76 | | |
83 | 77 | | |
84 | 78 | | |
85 | 79 | | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
| 80 | + | |
90 | 81 | | |
91 | 82 | | |
92 | 83 | | |
93 | 84 | | |
94 | 85 | | |
95 | 86 | | |
96 | 87 | | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
| 88 | + | |
101 | 89 | | |
102 | 90 | | |
103 | 91 | | |
104 | 92 | | |
105 | 93 | | |
106 | 94 | | |
107 | 95 | | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
| 96 | + | |
112 | 97 | | |
113 | 98 | | |
114 | 99 | | |
| |||
120 | 105 | | |
121 | 106 | | |
122 | 107 | | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
| 108 | + | |
127 | 109 | | |
128 | 110 | | |
129 | 111 | | |
| |||
405 | 387 | | |
406 | 388 | | |
407 | 389 | | |
408 | | - | |
409 | | - | |
410 | | - | |
411 | | - | |
| 390 | + | |
412 | 391 | | |
413 | 392 | | |
414 | 393 | | |
| |||
420 | 399 | | |
421 | 400 | | |
422 | 401 | | |
423 | | - | |
424 | | - | |
425 | | - | |
426 | | - | |
| 402 | + | |
427 | 403 | | |
428 | 404 | | |
429 | 405 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
| 56 | + | |
60 | 57 | | |
61 | 58 | | |
62 | 59 | | |
| |||
75 | 72 | | |
76 | 73 | | |
77 | 74 | | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
| 75 | + | |
82 | 76 | | |
83 | 77 | | |
84 | 78 | | |
| |||
0 commit comments