Skip to content

Single-argument panic!() with a non-static item gives confusing error message  #23685

@shepmaster

Description

@shepmaster
fn main() {
    let a = vec![1];
    let b = &a[0];

    panic!(b);
}

Generates the error:

err.rs:3:14: 3:15 error: `a` does not live long enough
err.rs:3     let b = &a[0];
                      ^
note: reference must be valid for the static lifetime...
err.rs:2:20: 6:2 note: ...but borrowed value is only valid for the block suffix following statement 0 at 2:19

This is quite confusing. The problem really is that we are trying to pass something to panic! / rt::begin_unwind that isn't static, but the error message doesn't implicate panic! at all.

Meta

rustc 1.0.0-dev (c6ca2205e 2015-03-19) (built 2015-03-19)
binary: rustc
commit-hash: c6ca2205eae522387237057812b7901a2c5d3906
commit-date: 2015-03-19
build-date: 2015-03-19
host: x86_64-apple-darwin
release: 1.0.0-dev

Originally from Stack Overflow

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions