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 4 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
|
☔ The latest upstream changes (presumably #150645) made this pull request unmergeable. Please resolve the merge conflicts. |
1 similar comment
|
☔ The latest upstream changes (presumably #150645) made this pull request unmergeable. Please resolve the merge conflicts. |
|
I think this PR needs further design regarding its interaction with the lint dead_code. @rustbot blocked |
4dc0f12 to
5ec9bbc
Compare
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
…uct, r=<try> Add a new lint `UNCONSTRUCTABLE_PUB_STRUCT` to detect unconstructable public structs
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
5ec9bbc to
e5cd4a2
Compare
|
The job Click to see the possible cause of the failure (guessed by this bot) |
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (51f5dfb): comparison URL. Overall result: ❌ regressions - BENCHMARK(S) FAILEDBenchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf. Next, please: If you can, justify the regressions found in this try perf run in writing along with @bors rollup=never ❗ ❗ ❗ ❗ ❗
❗ ❗ ❗ ❗ ❗ Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary 2.4%, secondary -1.7%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (secondary -7.3%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis perf run didn't have relevant results for this metric. Bootstrap: 510.687s -> 510.851s (0.03%) |
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