Skip to content

Better runtime panic message for RefCell borrow #74472

Closed
@CGQAQ

Description

$ RUST_BACKTRACE=0 cargo run
thread 'main' panicked at 'already mutably borrowed: BorrowError', /home/cg/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/cell.rs:797:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
$ RUST_BACKTRACE=1 cargo run
thread 'main' panicked at 'already mutably borrowed: BorrowError', /home/cg/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/cell.rs:797:9
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/libunwind.rs:86
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print_fmt
             at src/libstd/sys_common/backtrace.rs:78
   3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
             at src/libstd/sys_common/backtrace.rs:59
   4: core::fmt::write
             at src/libcore/fmt/mod.rs:1076
   5: std::io::Write::write_fmt
             at src/libstd/io/mod.rs:1537
   6: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:62
   7: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:49
   8: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:198
   9: std::panicking::default_hook
             at src/libstd/panicking.rs:218
  10: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:486
  11: rust_begin_unwind
             at src/libstd/panicking.rs:388
  12: core::panicking::panic_fmt
             at src/libcore/panicking.rs:101
  13: core::option::expect_none_failed
             at src/libcore/option.rs:1272
  14: core::result::Result<T,E>::expect
             at /home/cg/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/result.rs:963
  15: core::cell::RefCell<T>::borrow
             at /home/cg/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/cell.rs:797
  16: astar::main::{{closure}}
             at src/main.rs:15
  17: astar::astar::{{closure}}
             at src/main.rs:76               <-  this one is finally helpful
  18: <core::slice::Iter<T> as core::iter::traits::iterator::Iterator>::for_each
             at /home/cg/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/slice/mod.rs:3361
  19: astar::astar
             at src/main.rs:59
  20: astar::main
             at src/main.rs:9
  21: std::rt::lang_start::{{closure}}
             at /home/cg/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/rt.rs:67
  22: std::rt::lang_start_internal::{{closure}}
             at src/libstd/rt.rs:52
  23: std::panicking::try::do_call
             at src/libstd/panicking.rs:297
  24: std::panicking::try
             at src/libstd/panicking.rs:274
  25: std::panic::catch_unwind
             at src/libstd/panic.rs:394
  26: std::rt::lang_start_internal
             at src/libstd/rt.rs:51
  27: std::rt::lang_start
             at /home/cg/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/rt.rs:67
  28: main
  29: __libc_start_main
  30: _start
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
$ RUST_BACKTRACE=full cargo run
thread 'main' panicked at 'already mutably borrowed: BorrowError', /home/cg/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/cell.rs:797:9
stack backtrace:
   0:     0x5619946d4cd5 - backtrace::backtrace::libunwind::trace::h396c07d2071b43af
                               at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/libunwind.rs:86
   1:     0x5619946d4cd5 - backtrace::backtrace::trace_unsynchronized::h7aa0e4bb23d9c158
                               at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/mod.rs:66
   2:     0x5619946d4cd5 - std::sys_common::backtrace::_print_fmt::hd15ac5d4adcd355b
                               at src/libstd/sys_common/backtrace.rs:78
   3:     0x5619946d4cd5 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hec5354be8ccc3ecc
                               at src/libstd/sys_common/backtrace.rs:59
   4:     0x5619946f1c0c - core::fmt::write::h3d34909eeb4f225b
                               at src/libcore/fmt/mod.rs:1076
   5:     0x5619946d31b3 - std::io::Write::write_fmt::h1da287b3de55ed16
                               at src/libstd/io/mod.rs:1537
   6:     0x5619946d71e0 - std::sys_common::backtrace::_print::h4d206838e1ace354
                               at src/libstd/sys_common/backtrace.rs:62
   7:     0x5619946d71e0 - std::sys_common::backtrace::print::h1f778e9940ee5977
                               at src/libstd/sys_common/backtrace.rs:49
   8:     0x5619946d71e0 - std::panicking::default_hook::{{closure}}::h704403a56cbf5783
                               at src/libstd/panicking.rs:198
   9:     0x5619946d6f2c - std::panicking::default_hook::ha4567a10dec4ef8d
                               at src/libstd/panicking.rs:218
  10:     0x5619946d77c7 - std::panicking::rust_panic_with_hook::h88a1f16ec8a7bb20
                               at src/libstd/panicking.rs:486
  11:     0x5619946d73cb - rust_begin_unwind
                               at src/libstd/panicking.rs:388
  12:     0x5619946f1011 - core::panicking::panic_fmt::hbddb7fe6f399b81a
                               at src/libcore/panicking.rs:101
  13:     0x5619946f0e33 - core::option::expect_none_failed::h60849c4323f09783
                               at src/libcore/option.rs:1272
  14:     0x5619946c0e82 - core::result::Result<T,E>::expect::hc06879f926f77283
                               at /home/cg/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/result.rs:963
  15:     0x5619946cbd1a - core::cell::RefCell<T>::borrow::h94a5761e43c0b8ce
                               at /home/cg/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/cell.rs:797
  16:     0x5619946c83ae - astar::main::{{closure}}::h4bd19b8bbeff3fb4
                               at src/main.rs:15
  17:     0x5619946c9c2e - astar::astar::{{closure}}::ha54c2fee0c91f6ec
                               at src/main.rs:77
  18:     0x5619946cb543 - <core::slice::Iter<T> as core::iter::traits::iterator::Iterator>::for_each::h487a98a0c76eab18
                               at /home/cg/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/slice/mod.rs:3361
  19:     0x5619946c9148 - astar::astar::h64e3f7b80ab07f6b
                               at src/main.rs:59
  20:     0x5619946b982e - astar::main::hb1e7d447d1d97ade
                               at src/main.rs:9
  21:     0x5619946bc26b - std::rt::lang_start::{{closure}}::h3241643d841dae58
                               at /home/cg/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/rt.rs:67
  22:     0x5619946d7b98 - std::rt::lang_start_internal::{{closure}}::h6d21eebfa4beaf70
                               at src/libstd/rt.rs:52
  23:     0x5619946d7b98 - std::panicking::try::do_call::h560a27b87db38b9c
                               at src/libstd/panicking.rs:297
  24:     0x5619946d7b98 - std::panicking::try::h453d4afd696011f9
                               at src/libstd/panicking.rs:274
  25:     0x5619946d7b98 - std::panic::catch_unwind::h211d02671f23030f
                               at src/libstd/panic.rs:394
  26:     0x5619946d7b98 - std::rt::lang_start_internal::h464df2bbf46c7e7c
                               at src/libstd/rt.rs:51
  27:     0x5619946bc247 - std::rt::lang_start::h8ba4fc0dc1ea5693
                               at /home/cg/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/rt.rs:67
  28:     0x5619946ba7fa - main
  29:     0x7fe47f59b09b - __libc_start_main
  30:     0x5619946b917a - _start
  31:                0x0 - <unknown>

Backtrace number 17 is finally helpful.
What about just show it in panic info instead of thread 'main' panicked at 'already mutably borrowed: BorrowError', /home/cg/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/cell.rs:797:9 this crap

Or at least have a Backtrace mode that only shows user code trace, I think it would be helpful as I cannot tell whats the different between BACKTRACE=1 and BACKTRACE=full, both are very long and not intuitive

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: An issue proposing an enhancement or a PR with one.T-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions