Add a new lint UNCONSTRUCTABLE_PUB_STRUCT to detect unconstructable public structs#146440
Add a new lint UNCONSTRUCTABLE_PUB_STRUCT to detect unconstructable public structs#146440mu001999 wants to merge 5 commits into
UNCONSTRUCTABLE_PUB_STRUCT to detect unconstructable public structs#146440Conversation
|
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. |
b3b3a05 to
a1aaeb6
Compare
This comment has been minimized.
This comment has been minimized.
c6455d2 to
1ed009a
Compare
This comment has been minimized.
This comment has been minimized.
1ed009a to
60e74c5
Compare
This comment has been minimized.
This comment has been minimized.
60e74c5 to
f494476
Compare
This comment has been minimized.
This comment has been minimized.
f494476 to
01730b2
Compare
This comment has been minimized.
This comment has been minimized.
01730b2 to
3209e4a
Compare
This comment has been minimized.
This comment has been minimized.
3209e4a to
9aa49af
Compare
This comment has been minimized.
This comment has been minimized.
9aa49af to
7625326
Compare
|
@bors try |
This comment has been minimized.
This comment has been minimized.
|
💥 Test timed out after |
|
@bors try |
This comment has been minimized.
This comment has been minimized.
|
☔ The latest upstream changes (presumably #156670) made this pull request unmergeable. Please resolve the merge conflicts. |
|
@craterbot check |
|
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
View all comments
Add a new lint UNCONSTRUCTABLE_PUB_STRUCT to detect unconstructable public structs, based on the following observations:
And, the lint
UNCONSTRUCTABLE_PUB_STRUCTwon't affect the dead-code lint's result, but allow or deny dead-code lint may affect the result ofUNCONSTRUCTABLE_PUB_STRUCT