-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Make useless_ptr_null_checks smarter about some std functions #114494
Conversation
And look for it in the useless_ptr_null_checks lint
r? @thomcc (rustbot has picked a reviewer for you, use r? to override) |
f0f66b1
to
3d53495
Compare
fabfc2f
to
0071d57
Compare
Good point about the function that returns a reference, I suppose I've missed that. Also good point about the doc vs implementation discrepancy. I've removed the addition of the attribute from this PR and opened #114517 for discussion what to do about the discrepancy. It can then be resolved in a new PR. |
Add the attribute to standard library functions that are guaranteed to never return null pointers, as their originating data wouldn't allow it.
It was added by rust-lang#113657 for its purposes. Now it is not used any more, remove it, as we use the attr now.
0071d57
to
fed728d
Compare
This comment has been minimized.
This comment has been minimized.
fed728d
to
490eb7c
Compare
490eb7c
to
4b1bc27
Compare
Sorry about the delay here. I think the std side is fine, but I can't review the compiler changes. r? compiler |
@bors r |
☀️ Test successful - checks-actions |
Finished benchmarking commit (635c4a5): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 632.106s -> 632.885s (0.12%) |
This teaches the
useless_ptr_null_checks
lint that some std functions can't ever return null pointers, because they need to point to valid data, get references as input, etc.This is achieved by introducing an
#[rustc_never_returns_null_ptr]
attribute and adding it to these std functions (gated behind bootstrapcfg_attr
).Later on, the attribute could maybe be used to tell LLVM that the returned pointer is never null. I don't expect much impact of that though, as the functions are pretty shallow and usually the input data is already never null.
Follow-up of PR #113657
Fixes #114442