Open
Description
Code
struct Foo<'a> {
s1: &'a str,
s2: &'static str
}
fn make_foo<'a>(s: &'a str) -> Foo<'a> {
Foo {
s1: s,
s2: s
}
}
Current output
error: lifetime may not live long enough
--> src/lib.rs:9:13
|
6 | fn make_foo<'a>(s: &'a str) -> Foo<'a> {
| -- lifetime `'a` defined here
...
9 | s2: s
| ^ this usage requires that `'a` must outlive `'static`
error: could not compile `playground` (lib) due to previous error
Desired output
Something that indicates where the static lifetime comes from
error: lifetime may not live long enough
--> src/lib.rs:9:13
|
6 | fn make_foo<'a>(s: &'a str) -> Foo<'a> {
| -- lifetime `'a` defined here
...
9 | s2: s
| ^ this usage requires that `'a` must outlive `'static`
--
3 | s2: &'static str
| ^ `'static` lifetime specified here
Rationale and extra context
There's nothing in the function body or in the diagnostic to indicate why something must be 'static
if that information is associated with a type, so giving a hint would be helpful.
By comparison, it's much easier to figure out non-static things since the named lifetime 'a
clearly has a relationship with the type Foo
.
5 | fn make_foo<'a, 'b>(s: &'b str) -> Foo<'a> {
| -- -- lifetime `'b` defined here
| |
| lifetime `'a` defined here
6 | / Foo {
7 | | s1: s,
8 | | }
| |_____^ function was supposed to return data with lifetime `'a` but it is returning data with lifetime `'b`
Other cases
No response
Anything else?
No response