Skip to content

Resolve elided lifetimes in extern/foreign statics to 'static #148754

@BlankWasThere

Description

@BlankWasThere

The following code gives compiler error.

unsafe extern "C" {
    static WORLD: &str;
}
error[E0106]: missing lifetime specifier
 --> src\bin\runner.rs:6:24
  |
6 |     static WORLD: &str;
  |                   ^ expected named lifetime parameter

For more information about this error, try `rustc --explain E0106`.
error: could not compile `extern_test` (bin "runner") due to 1 previous error

What I expected: The compiler should automatically infer the lifetime of WORLD as 'static.

The bug is still there in nightly toolchain.

P.S. The imported library is a rust cdylib compiled together (and with the same compiler version).

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-FFIArea: Foreign function interface (FFI)A-lifetimesArea: Lifetimes / regionsC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-langRelevant to the language team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions