Skip to content

Function call in static results in compiler panic #26289

Closed
@grantslatton

Description

@grantslatton

See http://is.gd/0FO78Z

Code:

pub type TypeWithLifetime<'a> = Box<Fn() -> () + 'a>;

static static_closure : TypeWithLifetime<'static> = Box::new(|| {
    panic!()
});

fn main() {}

Error:

6:3 error: function calls in statics are limited to struct and enum constructors [E0015]
<anon>:4 static static_closure : TypeWithLifetime<'static> = Box::new(|| {
<anon>:5     panic!()
<anon>:6 });
error: internal compiler error: unexpected panic
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
note: run with `RUST_BACKTRACE=1` for a backtrace

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions