-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
#[rustc_inherit_overflow_checks] should be documented instead of replaced with e.g. Add::add calls. #81721
Comments
+1 to having something in the guidelines for what the correct approach is -- I only said this because it was mentioned to me in #45754 (comment) |
Wow, that's really old, thanks for tracking it down! I wasn't sure how far back it might go, I was only shown this pattern recently. |
Looks like that was potentially a misunderstanding of my comment at #36372 (comment), heh: I suggested replacing iter.fold(
0,
#[rustc_inherit_overflow_checks]
|a, b| a + b,
) |
…rk-Simulacrum Use `#[rustc_inherit_overflow_checks]` instead of Add::add etc. See rust-lang#81721
Regarding the suboptimal name, I wrote (in #81732 (comment)):
I also had an idea that might be useful for avoiding misuse in most cases:
|
(Note: this was originally posted as a comment on #62429 - also cc #35310 but not sure how relevant)
In #62429 (comment) @scottmcm said:
While adding more tests is better, I don't agree with removing the attribute. If anything the attribute should be better documented, but relying on more implicit mechanisms that internally use the attribute obscures the fact that something unusual is happening.
(i.e. that some of the behavior isn't decided by the crate being compiled, but by a downstream using crate)
The reason
Add::add
works at all is because the attribute is used in theimpl
s` for the integer types, e.g.:rust/library/core/src/ops/arith.rs
Lines 92 to 107 in 186f7ae
There's nothing magical about it being a trait call, you're just calling another function with
#[rustc_inherit_overflow_checks]
on it, instead of using#[rustc_inherit_overflow_checks]
yourself, and relying on generic/#[inline]
instantiation to get the behavior.The only reason the trait impls have the attribute is because of things generic over those traits, not to call directly.
EDIT: see also documentation issue by @m-ou-se at rust-lang/std-dev-guide#13
The text was updated successfully, but these errors were encountered: