Open
Description
Code
struct Foo;
impl Foo {
fn bar(&self) -> &() {
&()
}
}
fn takes_static(_s: &'static ()) {}
fn main() {
let foo = Foo;
let my_reference = foo.bar();
takes_static(my_reference);
}
Current output
error[E0597]: `foo` does not live long enough
--> src/main.rs:13:24
|
12 | let foo = Foo;
| --- binding `foo` declared here
13 | let my_reference = foo.bar();
| ^^^^^^^^^
| |
| borrowed value does not live long enough
| argument requires that `foo` is borrowed for `'static`
...
16 | }
| - `foo` dropped here while still borrowed
For more information about this error, try `rustc --explain E0597`.
Desired output
error[E0597]: `foo` does not live long enough
--> src/main.rs:13:24
|
12 | let foo = Foo;
| --- binding `foo` declared here
13 | let my_reference = foo.bar();
| ^^^^^^^^^
| |
| borrowed value does not live long enough
| argument requires that `foo` is borrowed for `'static`
|
15 | takes_static(my_reference);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: `my_reference` inferred to be `'static` here
...
16 | }
| - `foo` dropped here while still borrowed
For more information about this error, try `rustc --explain E0597`.
Rationale and extra context
the current error message doesn't mention where the 'static
bound comes from, making it seem very magical and not showing you where the problem actually arises. although obvious in a small example like this, it's pretty confusing in larger contexts.
Other cases
No response
Anything else?
No response