Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Cannot tell apart panic!() and assert!(false, "") in macro_backtrace() #82157

Open

Description

@AureaNoire

The two expressions:

panic!(); // A
assert!(false, "msg"); // B

Used to result in distinct macro_backtrace(). After updating to nightly-2021-02-14 (and I guess since #80851), the backtrace for both is identical, both listing the calls ["std::panic::panic_2015", "std::panic"].

IIUC, the latter should contain an additional core::assert or std::assert item in the backtrace.

Meta

rustc --version --verbose:

rustc 1.52.0-nightly (5fa22fe6f 2021-02-14)
binary: rustc
commit-hash: 5fa22fe6f821ac3801d05f624b123dda25fde32c
commit-date: 2021-02-14
host: x86_64-unknown-linux-gnu
release: 1.52.0-nightly
LLVM version: 11.0.1

Activity

  1. added
    C-bug
    on Feb 15, 2021
  2. jyn514 commented on Feb 16, 2021

    @jyn514
    Member

    @Aurel300 what do you mean by macro_backtrace? I can't find it in the docs for the standard library.

  3. AureaNoire commented on Feb 16, 2021

    @AureaNoire
    Author

    @jyn514 Yep, sorry, I should have linked to it. Yes, it is the Span::macro_backtrace you linked.

  4. added
    A-macros
    requires-nightly
    on Feb 16, 2021
  5. jyn514 commented on Feb 16, 2021

    @jyn514
    Member
  6. RodBurman commented on Jul 7, 2026

    @RodBurman

    Agreed as of rustc 1.96.1 (31fca3a 2026-06-26) the backtrace for panic! and assert! is very hard (if not impossible) to tell apart but isn't that what the "msg" in assert!(expr, "msg") is for? So suggestions to close this issue:

    1. Just close it, assuming people who need to highlight the assertion failure will add an appropriate message
    2. Or add a default message to assert!(expr) so it acts like assert!(expr, "Assert failed!") (we can discuss actual default message), this will highlight for those who forget to add their own message.
    3. Or add the default message (when required) then call std::assert(expr: bool, msg: &str) which can then print the message and panic if expr is false. (This may not be the best way to do this maybe deal with expr in the macro before calling assert). This inserts the call to std:assert into the backtrace of course, which was the original requirement,
  7. AureaNoire commented on Jul 15, 2026

    @AureaNoire
    Author

    Note that the context for the requirement is in program verification. A tool (in our case Prusti) will look through the program (mostly the MIR), figuring out which assertions can be violated. When reporting a verification error at a panic!(...) vs at an assert!(...) we want to report something else to the user -- "panic statement might be reachable" vs "assertion might not hold", respectively.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-macrosC-bugrequires-nightly

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions