Do not dereference uninhabited types refs in Clone implementations#3456
Do not dereference uninhabited types refs in Clone implementations#3456bors merged 1 commit intorust-lang:mainfrom
Conversation
A reference to an uninhabited type should never be dereferenced: this is UB. `Copy` should not be implemented on such a type, and an upcoming Clippy lint (`uninhabited_reference`) may flag such dereferences as suspicious. Since those types are not structs, they do not need to get `Copy` and `Clone` implementations. A `missing!` macro limits code duplication.
|
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @JohnTitor (or someone else) soon. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
|
Thanks! @bors r+ |
|
☀️ Test successful - checks-actions, checks-cirrus-freebsd-12, checks-cirrus-freebsd-13, checks-cirrus-freebsd-14 |
This is not quite correct: if the Now, this |
I agree. However, in the context of libc which necessarily deals with a lot of |
|
Oh I see! Then I totally agree, having these impls is a big footgun. Well the whole thing is quite footgunny but that too |
A reference to an uninhabited type should never be dereferenced: this is UB.
Copyshould not be implemented on such a type, and an upcoming Clippy lint (uninhabited_reference) may flag suchdereferences as suspicious.
Since those types are not structs, they do not need to get
CopyandCloneimplementations. Amissing!macro limits code duplication.