-
Notifications
You must be signed in to change notification settings - Fork 14k
Add a new lint UNCONSTRUCTABLE_PUB_STRUCT to detect unconstructable public structs
#146440
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: main
Are you sure you want to change the base?
Add a new lint UNCONSTRUCTABLE_PUB_STRUCT to detect unconstructable public structs
#146440
Conversation
|
r? @davidtwco rustbot has assigned @davidtwco. Use |
UNCONSTRUCTIBLE_PUB_STRUCT to detect unconstructible public structs
|
Would the lint fire on token structs that are public, have private fields, have no public constructor method, but expose a limited number of pre-constructed objects, e.g. through a static that contains an optional token? |
won't fire like private types used in such places |
480b1d7 to
021712b
Compare
|
Nominating for t-lang to decide whether we want this lint, then I'll review the implementation. Also, s/unconstructible/unconstructable. |
UNCONSTRUCTIBLE_PUB_STRUCT to detect unconstructible public structsUNCONSTRUCTABLE_PUB_STRUCT to detect unconstructable public structs
This comment was marked as resolved.
This comment was marked as resolved.
6075d81 to
497ad71
Compare
This comment has been minimized.
This comment has been minimized.
This comment was marked as resolved.
This comment was marked as resolved.
497ad71 to
b3b3a05
Compare
|
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
Does this trigger on structs that are intended only as marker types in generic parameters? |
Such types usually have intended private unit fields and this won't trigger on them. This will only trigger types with trivial fields but not be used or cannot be constructed. |
|
Are there examples of code in the wild that is affected by this lint? |
|
I worry about completeness here. If I have something like Musing: what if this was signature-based, say? Could it be phrased as "why is this |
|
We discussed this in today's @rust-lang/lang meeting. Was there any particular motivating use case that led to proposing this? Can you point to some code that motivated this? We wondered about potential corner cases, notably structs that are only constructed in unsafe code. For instance, something using Once those are addressed, we'd like to see the (triaged) results of a crater run with this lint marked as deny-by-default, so we can get an idea of 1) how widespread this is and 2) whether this catches any issues. |
|
Please renominate for lang when these answers are available. |
Add a new lint UNCONSTRUCTABLE_PUB_STRUCT to detect unconstructable public structs, based on the following observations: