Skip to content

Unusual Panic Location for Dividing by a Reference to Zero #114814

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

Closed
tim-burget opened this issue Aug 14, 2023 · 2 comments · Fixed by #114841
Closed

Unusual Panic Location for Dividing by a Reference to Zero #114814

tim-burget opened this issue Aug 14, 2023 · 2 comments · Fixed by #114841
Labels
C-bug Category: This is a bug. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Comments

@tim-burget
Copy link

I tried this code:

#[allow(unconditional_panic, unused)] // for minimal test case; doesn't cause problem
fn main() {
    1 / &0;
}

I expected to see this happen: program panics with main.rs or the actual location on disk of the standard library source code file that caused the panic given as the location

Instead, this happened: program gives /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/core/src/ops/arith.rs:484:1 (internal compiler location?) as the panic location

Meta

rustc --version --verbose:

rustc 1.71.1 (eb26296b5 2023-08-03)
binary: rustc
commit-hash: eb26296b556cef10fb713a38f3d16b9886080f26
commit-date: 2023-08-03
host: x86_64-pc-windows-msvc
release: 1.71.1
LLVM version: 16.0.5

I also checked that it happened in WSL:
rustc --version --verbose:

rustc 1.71.1 (eb26296b5 2023-08-03)
binary: rustc
commit-hash: eb26296b556cef10fb713a38f3d16b9886080f26
commit-date: 2023-08-03
host: x86_64-unknown-linux-gnu
release: 1.71.1
LLVM version: 16.0.5
Backtrace

No build errors, but the backtrace for the program also contains references to internal compiler locations that I would expect to point to the actual locations of standard library source files on disk, as well.

   0: std::panicking::begin_panic_handler
             at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library\std\src\panicking.rs:593
   1: core::panicking::panic_fmt
             at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library\core\src\panicking.rs:67
   2: core::panicking::panic
             at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library\core\src\panicking.rs:117
   3: core::ops::arith::impl$177::div
             at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26\library\core\src\ops\arith.rs:484
   4: core::ops::arith::impl$208::div
             at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26\library\core\src\internal_macros.rs:45
   5: bug::main
             at .\src\main.rs:3
   6: core::ops::function::FnOnce::call_once<void (*)(),tuple$<> >
             at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26\library\core\src\ops\function.rs:250

@tim-burget tim-burget added the C-bug Category: This is a bug. label Aug 14, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Aug 14, 2023
@tim-burget
Copy link
Author

Full output of cargo run (without RUST_BACKTRACE set):

    Finished dev [unoptimized + debuginfo] target(s) in 0.04s
     Running `target\debug\bug.exe`
thread 'main' panicked at 'attempt to divide by zero', /rustc/eb26296b556cef10fb713a38f3d16b9886080f26\library\core\src\ops\arith.rs:484:1
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
error: process didn't exit successfully: `target\debug\bug.exe` (exit code: 101)

@scottmcm
Copy link
Member

That goes through this trait implementation: https://doc.rust-lang.org/std/primitive.i32.html#impl-Div%3C%26i32%3E-for-i32

So technically it's happening there, but I agree that's not helpful.

Want to try making a PR to add #[track_caller] to those division and remainder implementations and see if it improves the location?

@saethlin saethlin added T-libs Relevant to the library team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Aug 15, 2023
bors added a commit to rust-lang-ci/rust that referenced this issue Oct 6, 2023
fix: add track_caller attr for div and mod

Fixes rust-lang#114814

`#[track_caller]` is works, r? `@scottmcm`
bors added a commit to rust-lang-ci/rust that referenced this issue Oct 14, 2023
add track_caller for arith ops

Fixes rust-lang#114814

`#[track_caller]` is works, r? `@scottmcm`
bors added a commit to rust-lang-ci/rust that referenced this issue Oct 19, 2023
add track_caller for arith ops

Fixes rust-lang#114814

`#[track_caller]` is works, r? `@scottmcm`
bors added a commit to rust-lang-ci/rust that referenced this issue Oct 23, 2023
add track_caller for arith ops

Fixes rust-lang#114814

`#[track_caller]` is works, r? `@scottmcm`
TaKO8Ki added a commit to TaKO8Ki/rust that referenced this issue Nov 9, 2023
add track_caller for arith ops

Fixes rust-lang#114814

`#[track_caller]` is works, r? ``@scottmcm``
@bors bors closed this as completed in b1e56de Nov 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants