Skip to content

Strange diagnostic message with a suggestion to annotate the lifetime #100442

Closed
@uselessgoddess

Description

@uselessgoddess

I wanted to issue a bug report in bumpalo and show an example of a vector error message from std
But I got a very strange suggest from compiler:

fn foo() -> impl Iterator<Item = usize> {
    let arena = Bump::new();
    // vec![in &arena; 1, 2, 3].into_iter()
    let mut vec = Vec::new_in(&arena);
    vec.push(1);
    vec.push(2);
    vec.push(3);
    vec.into_iter()
}

link to playground

error[E0597]: `arena` does not live long enough
  --> src\main.rs:8:31
   |
8  |     let mut vec = Vec::new_in(&arena);
   |                               ^^^^^^ borrowed value does not live long enough
...
12 |     vec.into_iter()
   |     --------------- opaque type requires that `arena` is borrowed for `'static`
13 | }
   | - `arena` dropped here while still borrowed
   |
help: you can add a bound to the opaque type to make it last less than `'static` and match `'static`
   |
12 |     vec.into_iter() + 'static
   |                     +++++++++

I even thought there was progress in type_ascription feature
In general, this message is very strange. Right now in growth I can't make arena live longer (I can, but not through annotations)

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsT-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