-
Notifications
You must be signed in to change notification settings - Fork 13k
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 offset must_use #72143
make offset must_use #72143
Conversation
Did you mean to annotate the intrinsic rather than the stable API? |
My thought process was:
|
We've added must_use to similar methods like wrapping_add in the past. r=me with it on the public API |
I would suggest expanding to all pointer methods which don't mutate self - that seems consistent to me. And presumably we should put the attribute on both the intrinsic and the stabilized methods? Seems odd to do just one. |
No one should be calling the intrinsics though. |
I don't mind not touching the intrinsics; I agree no one should be calling them. But the cost is tiny so seems like it wouldn't hurt to at least make sure our internal uses are also doing the right thing. I agree there's very little benefit. |
So, before I add them, what's the call here? I personally would choose to add them to both, but don't have a super strong preference. @sfackler , do you actively oppose adding them, or do you not mind if it's both? |
Sure, I have no objection to adding them to the intrinsics. |
356d64d
to
98eb699
Compare
Sigh, I do not know why this updated some submodules. trying to fix it now |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
https://djugei.github.io/bad-at-unsafe/ describes an error a user had when trying to use offset: > At first I just assumed that the .add() and .offset() methods on pointers would mutate the pointer. They do not. Instead they return a new pointer, which gets dropped silently if you don't use it. Unlike for example Result, which is must_use annotated.
98eb699
to
aea0186
Compare
Okay, this is ready for a re-review. I did the intrinsics as well as the functions that returned a new pointer. I'd appreciate someone checking that this is all accurate. :) |
@bors r+ rollup |
📌 Commit aea0186 has been approved by |
…sfackler make offset must_use https://djugei.github.io/bad-at-unsafe/ describes an error a user had when trying to use offset: > At first I just assumed that the .add() and .offset() methods on pointers would mutate the pointer. They do not. Instead they return a new pointer, which gets dropped silently if you don't use it. Unlike for example Result, which is must_use annotated. This PR only adds `offset`, because I wanted to float the idea; I'm imagining that there's more than just `add` and `offset` that could use this. I am also very open to re-wording the warning. r? @rust-lang/libs
Rollup of 2 pull requests Successful merges: - rust-lang#72143 (make offset must_use) - rust-lang#72307 (use the new interface to initialize conditional variables) Failed merges: r? @ghost
https://djugei.github.io/bad-at-unsafe/ describes an error a user had when trying to use offset:
This PR only adds
offset
, because I wanted to float the idea; I'm imagining that there's more than justadd
andoffset
that could use this. I am also very open to re-wording the warning.r? @rust-lang/libs