Skip to content

Wrong suggestion of using + static instead of <'static> for unions #71196

Closed

Description

Someone had this problem on discord, so creating an issue:

pub union Test<'t> {
    i: &'t i64,
    f: &'t f64,
}
thread_local! {
    static vals: RefCell<HashMap<i32, Vec<Vec<Test>>>> = RefCell::new(HashMap::new());
}

Rust suggests you to:

error[E0106]: missing lifetime specifier

   |
   |     static vals: RefCell<HashMap<i32, Vec<Vec<Test>>>> = RefCell::new(HashMap::new());
   |                                               ^^^^ help: consider giving it a 'static lifetime: `Test + 'static`
   |
   = help: this function's return type contains a borrowed value, but there is no value for it to be 
borrowed from

instead it should suggest to use Test<'static> and not <Test + 'static>

playground link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-bugCategory: This is a bug.D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.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