Skip to content

Conversation

y21
Copy link
Member

@y21 y21 commented Feb 13, 2023

Creating a zeroed uninhabited type such as ! or an empty enum with mem::zeroed() (or transmuting () to !) currently triggers this lint:

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 initialized

@rustbot
Copy link
Collaborator

rustbot commented Feb 13, 2023

r? @jackh726

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 13, 2023
@jackh726
Copy link
Member

r=me with rebase

@jackh726 jackh726 added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 18, 2023
@bors
Copy link
Collaborator

bors commented Feb 18, 2023

☔ The latest upstream changes (presumably #108211) made this pull request unmergeable. Please resolve the merge conflicts.

@y21 y21 force-pushed the no-zero-init-for-uninhabited branch from aa4d748 to 0610df9 Compare February 18, 2023 18:07
@y21
Copy link
Member Author

y21 commented Feb 18, 2023

Rebased and squashed the commits into one

@y21
Copy link
Member Author

y21 commented Feb 20, 2023

@jackh726, is there anything else I need to do here? Just making sure so it doesn't get lost or run into merge conflicts again.

@jackh726
Copy link
Member

Nope

@bors r+

@bors
Copy link
Collaborator

bors commented Feb 20, 2023

📌 Commit 0610df9 has been approved by jackh726

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 20, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 21, 2023
Rollup of 7 pull requests

Successful merges:

 - rust-lang#108000 (lint: don't suggest MaybeUninit::assume_init for uninhabited types)
 - rust-lang#108105 (Explain the default panic hook better)
 - rust-lang#108141 (Add rpitit queries)
 - rust-lang#108272 (docs: wrong naming convention in struct keyword doc)
 - rust-lang#108285 (remove unstable `pick_stable_methods_before_any_unstable` flag)
 - rust-lang#108289 (Name placeholder in some region errors)
 - rust-lang#108290 (Add a test for default trait method with RPITITs)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 4dea3a2 into rust-lang:master Feb 21, 2023
@rustbot rustbot added this to the 1.69.0 milestone Feb 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants