You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Many functions with rustc_inherit_overflow_checks should also have track_caller #119682
In general, if a library function panics due to invalid input, its best if the error message point to the function call and explain why the input was invalid. An overflow in a core library function with the #[rustc_inherit_overflow_checks] attribute is probably due to invalid input.
Assuming a function could only panic due to incorrect input, the only potential drawback to #[track_caller] I can see is the panic message not adequately explaining why the input was invalid. Until we get #111466, we can only pass the text of the overflow error. For div_euclid*, this is perfect. For next_multiple_of, this is sufficient. For advance_by, I'm not sure.
Adding the attribute is trivial. I'm only making this issue to ask if/what functions I should add the attribute to and if I need to.
* Edit: The division function might be a confusing example since it doesn't care about #[rustc_inherit_overflow_checks]. However, it should have #[track_caller] like the others.
It doesn't seem like #119726 fixes all such missed #[track_caller].
The #119726 doesn't add #[track_caller] at least to next_multiple_of and advance_by that is mentioned in this issue.
There are panicking functions with #[rustc_inherit_overflow_checks] that miss #[track_caller]:
Possibly all functions that require #[rustc_inherit_overflow_checks] should have #[track_caller] and there are still some functions with redundant #[rustc_inherit_overflow_checks].
thread '<unnamed>' panicked at /home/zheland/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/num/mod.rs:1199:5:
attempt to multiply with overflow
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread '<unnamed>' panicked at /home/zheland/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/num/mod.rs:1199:5:
attempt to add with overflow
thread '<unnamed>' panicked at /home/zheland/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/num/mod.rs:1199:5:
attempt to add with overflow
thread '<unnamed>' panicked at /home/zheland/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/num/mod.rs:383:5:
attempt to multiply with overflow
thread '<unnamed>' panicked at /home/zheland/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/num/mod.rs:383:5:
attempt to add with overflow
thread '<unnamed>' panicked at /home/zheland/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/num/mod.rs:383:5:
attempt to negate with overflow
thread '<unnamed>' panicked at /home/zheland/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/arith.rs:712:1:
attempt to negate with overflow
thread '<unnamed>' panicked at /home/zheland/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/bit.rs:496:1:
attempt to shift left with overflow
thread '<unnamed>' panicked at /home/zheland/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/bit.rs:496:1:
attempt to shift left with overflow
thread '<unnamed>' panicked at /home/zheland/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/bit.rs:614:1:
attempt to shift right with overflow
thread '<unnamed>' panicked at /home/zheland/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/bit.rs:614:1:
attempt to shift right with overflow
thread '<unnamed>' panicked at /home/zheland/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/bit.rs:950:1:
attempt to shift left with overflow
thread '<unnamed>' panicked at /home/zheland/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/bit.rs:950:1:
attempt to shift left with overflow
thread '<unnamed>' panicked at /home/zheland/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/bit.rs:1032:1:
attempt to shift right with overflow
thread '<unnamed>' panicked at /home/zheland/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/bit.rs:1032:1:
attempt to shift right with overflow
thread '<unnamed>' panicked at /home/zheland/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/iter/adapters/enumerate.rs:63:22:
attempt to add with overflow
Expected something like:
...
thread '<unnamed>' panicked at src/main.rs:18:20:
attempt to negate with overflow
...
thread '<unnamed>' panicked at src/main.rs:31:22:
attempt to shift left with overflow
...
@dtolnay, could you please review my previous comment. I think that issue is not fixed and should be reopened.
And since it looks like a simple fix and I've already started getting into it, I can double-check the details and try to prepare a PR for the fix.
Activity
dtolnay commentedon Apr 5, 2024
Fixed by #119726.
zheland commentedon Dec 2, 2024
It doesn't seem like #119726 fixes all such missed
#[track_caller].The #119726 doesn't add
#[track_caller]at least tonext_multiple_ofandadvance_bythat is mentioned in this issue.There are panicking functions with
#[rustc_inherit_overflow_checks]that miss#[track_caller]:pow,next_multiple_of,next_power_of_two.pow,next_multiple_of,abs.neg.shl,shr,shl_assign,shr_assign.Functions for which
#[rustc_inherit_overflow_checks]seems redundant:is_multiple_of.position.Additionally
#[rustc_inherit_overflow_checks]without#[track_caller]is often used incount-like functions iterators functions in:Possibly all functions that require
#[rustc_inherit_overflow_checks]should have#[track_caller]and there are still some functions with redundant#[rustc_inherit_overflow_checks].Example:
With:
Results in:
Expected something like:
Version (last nightly):
zheland commentedon Jan 11, 2025
@dtolnay, could you please review my previous comment. I think that issue is not fixed and should be reopened.
And since it looks like a simple fix and I've already started getting into it, I can double-check the details and try to prepare a PR for the fix.