Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[diagnostics] Add mentions to Copy types being valid for union fields #94031

Conversation

danielhenrymantilla
Copy link
Contributor

@danielhenrymantilla danielhenrymantilla commented Feb 15, 2022

This came up from some user on Discord which was using a T : PrimitiveInt generic type, and they wanted to use in a union. Rather than adding a Copy bound, they started pondering about the ManuallyDrop<T> road, and how to correctly use unsafe to perform the drops.

Screen Shot 2022-02-15 at 22 28 34

So, it seemed like the error message for types with potential drop glue on union fields could be improved to also mention the Copy alternative, since in many cases where unions are concerned, people are dealing with PODs / Copy types anyways 🙂


@rustbot modify labels: +A-diagnostics +D-terse

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Feb 15, 2022
@rust-highfive
Copy link
Collaborator

r? @davidtwco

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 15, 2022
@danielhenrymantilla danielhenrymantilla force-pushed the diagnostics/union-drop-suggest-copy-bound-alternative branch from 5a023ee to 9cc597b Compare February 15, 2022 21:34
@rustbot rustbot added A-diagnostics Area: Messages for errors, warnings, and lints D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. labels Feb 15, 2022
Copy link
Member

@davidtwco davidtwco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a straight forward improvement to me, r=me once my nittiest of nitpicks is resolved.

compiler/rustc_typeck/src/check/check.rs Outdated Show resolved Hide resolved
@danielhenrymantilla danielhenrymantilla force-pushed the diagnostics/union-drop-suggest-copy-bound-alternative branch from 4657f1c to 43e6df1 Compare February 16, 2022 12:28
@danielhenrymantilla danielhenrymantilla force-pushed the diagnostics/union-drop-suggest-copy-bound-alternative branch from 43e6df1 to 6d2cdbe Compare February 16, 2022 12:29
@davidtwco
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Feb 16, 2022

📌 Commit 6d2cdbe has been approved by davidtwco

@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-review Status: Awaiting review from the assignee but also interested parties. labels Feb 16, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Feb 16, 2022
…on-drop-suggest-copy-bound-alternative, r=davidtwco

[diagnostics] Add mentions to `Copy` types being valid for `union` fields

This came up from some user on Discord which was using a `T : PrimitiveInt` generic type, and they wanted to use in a `union`. Rather than adding a `Copy` bound, they started pondering about the `ManuallyDrop<T>` road, and how to correctly use `unsafe` to perform the drops.

<img width="648" alt="Screen Shot 2022-02-15 at 22 28 34" src="https://user-images.githubusercontent.com/9920355/154152496-8f9be74b-ad59-4724-8f9e-48b446774e06.png">

  - [Discord link](https://discord.com/channels/442252698964721669/443150878111694848/943092778534072320)

So, it seemed like the error message for types with potential drop glue on `union` fields could be improved to also mention the `Copy` alternative, since in many cases where `union`s are concerned, people are dealing with PODs / `Copy` types anyways 🙂

___

`@rustbot` modify labels: +A-diagnostics +D-terse
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 17, 2022
…askrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#89869 (Add documentation to more `From::from` implementations.)
 - rust-lang#93479 (Use `optflag` for `--report-time`)
 - rust-lang#93693 (Suggest deriving required supertraits)
 - rust-lang#93981 (Fix suggestion to slice if scurtinee is a reference to `Result` or `Option`)
 - rust-lang#93996 (Do not suggest "is a function" for free variables)
 - rust-lang#94030 (Correctly mark the span of captured arguments in `format_args!()`)
 - rust-lang#94031 ([diagnostics] Add mentions to `Copy` types being valid for `union` fields)
 - rust-lang#94064 (Update dist-x86_64-musl to Ubuntu 20.04)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 91f70a8 into rust-lang:master Feb 17, 2022
@rustbot rustbot added this to the 1.60.0 milestone Feb 17, 2022
@danielhenrymantilla danielhenrymantilla deleted the diagnostics/union-drop-suggest-copy-bound-alternative branch February 17, 2022 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. 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.

5 participants