-
Notifications
You must be signed in to change notification settings - Fork 13.8k
repr(transparent): do not consider repr(C) types to be 1-ZST #147185
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
base: master
Are you sure you want to change the base?
Conversation
rustbot has assigned @petrochenkov. Use |
@bors try |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@craterbot check |
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
🚧 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
🎉 Experiment
Footnotes
|
This found
EDIT: It later got confirmed that these crates indeed already trigger the lint before this PR. |
@bors try |
repr(transparent): do not consider repr(C) types to be 1-ZST
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
🚧 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
🎉 Experiment
Footnotes
|
Sorry, I should have marked this as a draft. This also needs t-lang approval and if we are touching this logic anyway I am considering also ruling out uninhabited types.
|
@bors try |
repr(transparent): do not consider repr(C) types to be 1-ZST
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
💔 Test for 507f846 failed: CI. Failed jobs:
|
So... apparently the Let's see if trying again helps. 🤷 |
repr(transparent): do not consider repr(C) types to be 1-ZST
This comment has been minimized.
This comment has been minimized.
💔 Test for 91f7b9e failed: CI. Failed jobs:
|
This comment has been minimized.
This comment has been minimized.
I guess hyper has a problematic transparent type somewhere and the PGO build swallows the error message...
|
@bors try |
repr(transparent): do not consider repr(C) types to be 1-ZST
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
💔 Test for 3f96790 failed: CI. Failed jobs:
|
This comment has been minimized.
This comment has been minimized.
The odd thing is that when I build hyper locally with the rustc from this branch, it just works. Even when I use the specific version and lockfile from the rustc-perf repo. EDIT: ah, I have to add |
Okay I managed to figure out where hyper fails to build -- I spun off discussion of uninhabited types to #147588; this will not be part of this PR. |
b142623
to
5f04f0f
Compare
@rust-lang/lang I am proposing we no longer accept #[repr(C)]
struct ReprCZst([u8; 0]);
#[repr(transparent)]
struct Wrap(ReprCZst, i32); The reason for this is two-fold:
We did a crater run and found 0 cases of code that actually relied on a The way this PR implements the FCW is by extending the existing FCW So the questions for you are:
|
5f04f0f
to
28ced79
Compare
| | ||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | ||
= note: for more information, see issue #78586 <https://github.com/rust-lang/rust/issues/78586> | ||
= note: this enum contains `NonExhaustiveEnum`, which is marked with `#[non_exhaustive]`, and makes it not a breaking change to become non-zero-sized in the future. |
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.
The previous wording here made no sense -- it said "this enum contains NonExhaustiveEnum
", but what it meant was that NonExhaustiveEnum
is an enum. The span points at InternalIndirection<NonExhaustiveEnum>
which is not an enum!
So I changed it to just "this field contains ...".
28ced79
to
2e68050
Compare
Context: rust-lang/unsafe-code-guidelines#552
This experiments with a suggestion by @RustyYato to stop considering repr(C) types as 1-ZST for the purpose of repr(transparent). If we go with rust-lang/rfcs#3845 (or another approach for fixing repr(C)), they will anyway not be ZST on all targets any more, so this removes a portability hazard. Furthermore, zero-sized repr(C) structs may have to be treated as non-ZST for the win64 ABI (at least that's what gcc/clang do), so allowing them to be ignored in repr(transparent) types is not entirely coherent.
Turns out we already have an FCW for repr(transparent), namely #78586. This extends that lint to also check for repr(C).
TODO: update the lint name and wording to account for its extended scope.