-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Fix incorrect clashing_extern_declarations warnings. #73990
Conversation
ee6f54b
to
b9efacf
Compare
d22ea6a
to
7bba12b
Compare
7bba12b
to
d283429
Compare
d283429
to
b5aab18
Compare
I'm still working on getting |
136fe20
to
f84b951
Compare
Alright, this good for re-review -- I have |
f84b951
to
c9ccc99
Compare
Broadly lgtm, left 2 minor comments, r=me once resolved. |
c9ccc99
to
68b8a09
Compare
The changes have been applied. This is good to go. e: Oops, had some unstaged formatting changes. This will be good to go once CI passes. |
68b8a09
to
9182910
Compare
Note that I've also added a few additional commits; they fix an assertion failure and false negative I noticed while working on this. |
☔ The latest upstream changes (presumably #74342) made this pull request unmergeable. Please resolve the merge conflicts. |
470d759
to
da009d5
Compare
☔ The latest upstream changes (presumably #74468) made this pull request unmergeable. Please resolve the merge conflicts. |
da009d5
to
cfcb282
Compare
cfcb282
to
004c1c1
Compare
An example of an FFI-safe enum conversion is when converting Option<NonZeroUsize> to usize. Because the Some value must be non-zero, rustc can use 0 to represent the None variant, making this conversion is safe. Furthermore, it can be relied on (and removing this optimisation already would be a breaking change).
Co-authored-by: Teymour Aldridge <[email protected]>
- Make `is_repr_nullable_ptr` freestanding again to avoid usage of ImproperCTypesVisitor in ClashingExternDeclarations (and don't accidentally revert the ParamEnv::reveal_all() fix from a week earlier) - Revise match condition for 1 Adt, 1 primitive - Generalise check for non-null type so that it would also work for ranges which exclude any single value (all bits set, for example) - Make is_repr_nullable_ptr return the representable type instead of just a boolean, to avoid adding an additional, independent "source of truth" about the FFI-compatibility of Option-like enums. Also, rename to `repr_nullable_ptr`.
004c1c1
to
0bd292d
Compare
I've just done another rebase -- @nagisa, are you available to review and approve? I'd like to get this merged soon so that these fixes can be backported to beta, and so I can try a crater check run with this lint as deny-by-default. |
@bors r+ |
📌 Commit 0bd292d has been approved by |
discussed at T-compiler meeting. We decided the complexity of this PR, weighed against the bug it fixes, does not warrant a backport. However, we agreed that a PR that just changed the lint on beta to be allow-by-default would be a reasonable thing to put on the beta branch. |
@rustbot modify labels: -beta-nominated |
☀️ Test successful - checks-actions, checks-azure |
…=Mark-Simulacrum [beta] Make ClashingExternDeclarations Allow by default. As per rust-lang#73990 (comment), this PR changes `clashing_extern_declarations` to allow-by-default to sidestep current false positives & negatives on the beta branch. Note that the changes to fix the issue properly have been merged to master (see rust-lang#73990), but those changes will have to arrive on the next release train.
/// can, return the the type that `ty` can be safely converted to, otherwise return `None`. | ||
/// Currently restricted to function pointers, boxes, references, `core::num::NonZero*`, | ||
/// `core::ptr::NonNull`, and `#[repr(transparent)]` newtypes. | ||
/// FIXME: This duplicates code in codegen. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does anyone involved still remember which code in codegen this duplicates? The comment as-is is unfortunately not very helpful since it is unclear where that duplication is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah never mind, this comment predates this PR, it just got moved here.
Fixes #73735, fixes #73872.
Fix clashing_extern_declarations warning for
#[repr(transparent)]
structs and safely-FFI-convertible enums, and not warning for clashes of struct members of different types, but the same size.r? @nagisa