Resolve elided lifetimes in extern/foreign statics to `'static`
Open
Nobody has claimed this yet.
A-FFI
A-lifetimes
C-enhancement
T-lang
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
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).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue from src\bin\runner.rs using the shown unsafe extern "C" declaration on a nightly toolchain, then trace the E0106 diagnostic for the elided lifetime. Done means the extern static declaration compiles with its lifetime inferred as 'static and the relevant compiler tests pass.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100