Skip to content

Calling unwind via function pointer leads to odd panic message #68178

@RalfJung

Description

@RalfJung

I was playing around with function pointers to track_caller methods (which doesn't seem entirely implemented yet) and arrived at the following testcase:

fn call_it<T>(f: fn(T), x: T) {
    f(x);
}

fn main() {
    call_it(Result::unwrap, Err(0));
}

On stable, this behaves as expected:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: 0', src/libcore/result.rs:1165:5

On the latest nightly though, the message is different:

thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', src/libstd/panicking.rs:369:15

The line number points at this:

let loc = info.location().unwrap(); // The current implementation always returns Some

Two things seem odd here for me:

  • I am actually surprised that this does not ICE, given that the ReifyShim stuff does not seem entirely implemented (at least this test still ICEs).
  • But the actual main bug here is that the comment about "always returns Some" seems wrong, so this panics at the wrong place. Clearly, the message shouldn't talk about Option::unwrap() when the actual panic is caused by a Result::unwrap.

Cc @anp

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.F-track_caller`#![feature(track_caller)]`T-compilerRelevant to the compiler 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