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

repr_transparent_external_private_fields: special-case some std types #129487

Merged

Conversation

GrigorenkoPV
Copy link
Contributor

Fixes #129470

@rustbot label +A-lint +L-repr_transparent_external_private_fields

@rustbot
Copy link
Collaborator

rustbot commented Aug 23, 2024

r? @nnethercote

rustbot has assigned @nnethercote.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@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. T-libs Relevant to the library team, which will review and decide on the PR/issue. A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. L-repr_transparent_external_private_fields Lint: repr_transparent_external_private_fields labels Aug 23, 2024
tcx.as_lang_item(def.did()),
Some(LangItem::UnsafeCell | LangItem::ManuallyDrop | LangItem::MaybeUninit)
) || matches!(
tcx.get_diagnostic_name(def.did()),
Copy link
Member

@compiler-errors compiler-errors Aug 23, 2024

Choose a reason for hiding this comment

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

Diagnostic items should not be used in a way that affects whether something is linted. They should only be used to change the quality of a diagnostic (i.e. its labels or its message). These should be turned into lang items.

Copy link
Member

Choose a reason for hiding this comment

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

Also, is there a reason why we don't apply this to any repr(transparent) ADT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, is there a reason why we don't apply this to any repr(transparent) ADT?

As mentioned in the original issue

More generally, quoting the nomicon:

This repr is only considered part of the public ABI of a type if either the single field is pub, or if its layout is documented in prose. Otherwise, the layout should not be relied upon by other crates.

So, in ManuallyDrop's case, the single field is not pub, but the layout is documented in prose and so should be considered part of the ABI. Is it possible there are other types out there with such a layout guarantee in prose, which might also be incorrectly flagged by this lint?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These should be turned into lang items.

Is there some sort of FCP required for this?

Copy link
Member

Choose a reason for hiding this comment

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

No, you just need to do something like this: f4f57bf

Copy link
Member

Choose a reason for hiding this comment

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

For Pin we also guarantee the layout in prose.

I think it would be better to introduce an internal attribute (e.g. rustc_pub_transparent) to mark those types rather than special case them all individually just for this lint.

Copy link
Member

Choose a reason for hiding this comment

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

Yep, I think a builtin attr would be nice.

@GrigorenkoPV
Copy link
Contributor Author

@rustbot label +A-lang-item

Cell & SyncUnsafeCell are now lang items. As per #129487 (comment)

@rustbot rustbot added the A-lang-item Area: Language items label Aug 23, 2024
@compiler-errors compiler-errors removed the A-lang-item Area: Language items label Aug 24, 2024
@compiler-errors
Copy link
Member

Could you please rework this by adding a new attribute which tracks if the repr is "public" via rustc_pub_transparent? Then please squash the history since we don't need to track adding a diagnostic item and a lang item if it didn't make it into the final revision.

@compiler-errors compiler-errors 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 Aug 24, 2024
@GrigorenkoPV GrigorenkoPV force-pushed the repr_transparent_external_private_fields branch from fc365d5 to 814185a Compare August 24, 2024 17:40
@GrigorenkoPV
Copy link
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 24, 2024
@GrigorenkoPV GrigorenkoPV force-pushed the repr_transparent_external_private_fields branch from b3432e2 to fc022ad Compare August 24, 2024 18:53
@compiler-errors
Copy link
Member

Then please squash the history since we don't need to track adding a diagnostic item and a lang item if it didn't make it into the final revision.

@rustbot author

@rustbot rustbot 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 Aug 24, 2024
rustc_attr!(
rustc_pub_transparent, Normal, template!(Word),
WarnFollowing, EncodeCrossCrate::Yes,
"rustc_pub_transparent is supposed to be used in libstd only",
Copy link
Member

Choose a reason for hiding this comment

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

give this a better description

(rustc_deprecated_safe_2024 also has a bad description, but that's unrelated)

@GrigorenkoPV
Copy link
Contributor Author

Then please squash the history since we don't need to track adding a diagnostic item and a lang item if it didn't make it into the final revision.

I have force-pushed a new version, where those commits do not even exist.

@compiler-errors
Copy link
Member

Please squash this still. We don't need a FIVE commit PR for a simple attribute addition.

@compiler-errors
Copy link
Member

Like, this is a pretty basic PR; it does not need to document every single tiny step that you took in implementing something. This PR touches about as many files in the compiler as the number of commits, so I feel like it's a bit excessive.

@compiler-errors
Copy link
Member

Sorry, though; I saw 5 commits before and saw 5 commits after so I didn't realize that you actually ended up just writing 4 more commits just to add an internal attribute, lol.

@GrigorenkoPV
Copy link
Contributor Author

No problem, I will squash them, as they have indeed got a bit too small but numerous

@GrigorenkoPV GrigorenkoPV force-pushed the repr_transparent_external_private_fields branch from fc022ad to 06f2d73 Compare August 24, 2024 20:12
@GrigorenkoPV
Copy link
Contributor Author

@rustbot ready
i think

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 24, 2024
Copy link
Member

@compiler-errors compiler-errors left a comment

Choose a reason for hiding this comment

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

Thanks!

@compiler-errors
Copy link
Member

@bors r+

@bors
Copy link
Collaborator

bors commented Aug 24, 2024

📌 Commit 06f2d73 has been approved by compiler-errors

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-review Status: Awaiting review from the assignee but also interested parties. labels Aug 24, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Aug 25, 2024
…rnal_private_fields, r=compiler-errors

repr_transparent_external_private_fields: special-case some std types

Fixes rust-lang#129470

`@rustbot` label +A-lint +L-repr_transparent_external_private_fields
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 25, 2024
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#128919 (Add an internal lint that warns when accessing untracked data)
 - rust-lang#129134 (bootstrap: improve error recovery flags to curl)
 - rust-lang#129416 (library: Move unstable API of new_uninit to new features)
 - rust-lang#129459 (handle stage0 `cargo` and `rustc` separately)
 - rust-lang#129487 (repr_transparent_external_private_fields: special-case some std types)
 - rust-lang#129511 (Update minifier to 0.3.1)
 - rust-lang#129523 (Make `rustc_type_ir` build on stable)
 - rust-lang#129546 (Get rid of `predicates_defined_on`)

r? `@ghost`
`@rustbot` modify labels: rollup
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Aug 25, 2024
…rnal_private_fields, r=compiler-errors

repr_transparent_external_private_fields: special-case some std types

Fixes rust-lang#129470

``@rustbot`` label +A-lint +L-repr_transparent_external_private_fields
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 25, 2024
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#129091 (add Box::as_ptr and Box::as_mut_ptr methods)
 - rust-lang#129134 (bootstrap: improve error recovery flags to curl)
 - rust-lang#129416 (library: Move unstable API of new_uninit to new features)
 - rust-lang#129459 (handle stage0 `cargo` and `rustc` separately)
 - rust-lang#129487 (repr_transparent_external_private_fields: special-case some std types)
 - rust-lang#129511 (Update minifier to 0.3.1)
 - rust-lang#129523 (Make `rustc_type_ir` build on stable)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 25, 2024
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#129091 (add Box::as_ptr and Box::as_mut_ptr methods)
 - rust-lang#129134 (bootstrap: improve error recovery flags to curl)
 - rust-lang#129416 (library: Move unstable API of new_uninit to new features)
 - rust-lang#129459 (handle stage0 `cargo` and `rustc` separately)
 - rust-lang#129487 (repr_transparent_external_private_fields: special-case some std types)
 - rust-lang#129511 (Update minifier to 0.3.1)
 - rust-lang#129523 (Make `rustc_type_ir` build on stable)

r? `@ghost`
`@rustbot` modify labels: rollup
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Aug 25, 2024
…, r=tgross35

gitignore: ignore ICE reports regardless of directory

Quite often when working on compiler I end up running into ICEs during the standard library compilation.

These ICEs generate reports in `/library/` and not at the root of the repo, so they aren't `gitignore`d.

I finally ended up committing one today, by accident: rust-lang#129487 (comment)
@bors bors merged commit 9c59e97 into rust-lang:master Aug 25, 2024
6 checks passed
@rustbot rustbot added this to the 1.82.0 milestone Aug 25, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Aug 25, 2024
Rollup merge of rust-lang#129487 - GrigorenkoPV:repr_transparent_external_private_fields, r=compiler-errors

repr_transparent_external_private_fields: special-case some std types

Fixes rust-lang#129470

```@rustbot``` label +A-lint +L-repr_transparent_external_private_fields
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Aug 25, 2024
…, r=tgross35

gitignore: ignore ICE reports regardless of directory

Quite often when working on compiler I end up running into ICEs during the standard library compilation.

These ICEs generate reports in `/library/` and not at the root of the repo, so they aren't `gitignore`d.

I finally ended up committing one today, by accident: rust-lang#129487 (comment)
@GrigorenkoPV GrigorenkoPV deleted the repr_transparent_external_private_fields branch August 26, 2024 04:37
@GrigorenkoPV
Copy link
Contributor Author

Thank you a lot for the review!

rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Aug 26, 2024
Rollup merge of rust-lang#129518 - GrigorenkoPV:gitignore-library-ice, r=tgross35

gitignore: ignore ICE reports regardless of directory

Quite often when working on compiler I end up running into ICEs during the standard library compilation.

These ICEs generate reports in `/library/` and not at the root of the repo, so they aren't `gitignore`d.

I finally ended up committing one today, by accident: rust-lang#129487 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. L-repr_transparent_external_private_fields Lint: repr_transparent_external_private_fields 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. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

repr_transparent_external_private_fields lint fires on ManuallyDrop containing a ZST
6 participants