Merge and reframe strict_provenance_lints#157575
Conversation
This comment has been minimized.
This comment has been minimized.
d8b8b2f to
6e531ef
Compare
|
r? @mu001999 rustbot has assigned @mu001999. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
Not sure what the right process for renaming unstable lints. Does it need a lang FCP or is that only for new stable lints? Also: cc @RalfJung |
|
Since this is unstable it doesn't need heavy process.
Actually an easier approach might be for me to become the champion for these lints, so I can approve changes to them. I'll ask about that on Zulip. |
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.
0274a30 to
fda7bff
Compare
There was a problem hiding this comment.
Thanks for your patience! I'm finally back from my trip and can start catching up with my backlog.
Mostly minor comments, but I am kind of concerned about the suggestions these lints emit. That's pre-existing though -- it does not block this PR, but I am not sure we want to stabilize this as-is.
@rustbot author
| LL - let addr: usize = &x as *const u8 as usize; | ||
| LL + let addr: usize = (&x as *const u8).addr(); |
There was a problem hiding this comment.
This suggestion seems kind of dangerous -- it is almost always wrong to just apply this, because the cast back to a pointer somewhere else in the code also needs to be adjusted. Do we really want such a suggestions?
There was a problem hiding this comment.
I don't think it's almost always wrong (e.g., in #156832, it's correct in all but one instance because most cases just inspected the address and never cast back to pointer). There's also the mitigating factor that the lint will frequently also point out the corresponding int2ptr cast so you can consider them at roughly the same time.
I agree it would be safer to suggest exposed provenance APIs, because there are cases where applying the suggestion leads to subtle UB. But I'd like to propose that change separately in a follow-up PR.
There was a problem hiding this comment.
Agreed with postponing this discussion/change to a later PR. I'll add a note to the tracking issue.
|
Reminder, once the PR becomes ready for a review, use |
fda7bff to
3d31306
Compare
|
This PR was rebased onto a different main 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. |
|
@rustbot ready |
|
@bors r+ rollup |
This comment has been minimized.
This comment has been minimized.
What is this?This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.Comparing 1182320 (parent) -> b4486ca (this PR) Test differencesShow 10 test diffs10 doctest diffs were found. These are ignored, as they are noisy. Test dashboardRun cargo run --manifest-path src/ci/citool/Cargo.toml -- \
test-dashboard b4486cacf58926f02e451d96e71e20882faf5453 --output-dir test-dashboardAnd then open Job duration changes
How to interpret the job duration changes?Job durations can vary a lot, based on the actual runner instance |
|
Finished benchmarking commit (b4486ca): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis perf run didn't have relevant results for this metric. Max RSS (memory usage)Results (secondary 2.7%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (secondary 1.2%)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: 485.632s -> 486.992s (0.28%) |
View all comments
There does not seem to be any good reason to have separate lints for ptr2int and int2ptr casts. The main reason to enable this lint is to help with replacing
ascasts with strict provenance APIs (if possible) or explicit provenance APIs (when needed). That applies equally to both directions.Merging the lints requires coming up with new name and lint explanation. This is a good chance to reconsider the purpose and messaging of the lints which have been essentially unchanged since the early days of the "strict provenance experiment". For reasons described below, I called the merged lint
implicit_provenance_casts, rewrote its explanation from scratch, and made some changes to diagnostics.First, the lint is not (only) about strict provenance any more. While strict provenance is often the best fix, migrating
ascasts to exposed provenance APIs also silences the lint. The exposed provenance APIs aren't any better for Miri and CHERI, but at least provenance considerations are made explicit, not picked up as side effect of theaskeyword. (Banning use of exposed provenance APIs can be done with clippy's existingdisallowed_methodslint.)Second, provenance is now officially part of the language and prominently explained in the
std::ptrdocumentation. The new lint refers to those docs and is more consistent with them.Third, while strict provenance is encouraged whenever possible, exposed provenance is also part of the language and here to stay. Indeed, if we eventually enable the lint by default and make it
cargo fix-able to keep the ecosystem migration manageable, we may want to suggest exposed provenance APIs to err on the side of not introducing UB. Thus, I made the diagnostics more neutral and descriptive. I've kept the suggestions that introduce strict provenance APIs, but we may want to reconsider this later.Tracking issue: #130351