Open
Description
Code
fn input(_: &'static str) {}
fn main() {
let x = String::new();
input(&x);
}
Current output
error[E0597]: `x` does not live long enough
--> src/main.rs:5:11
|
4 | let x = String::new();
| - binding `x` declared here
5 | input(&x);
| ------^^-
| | |
| | borrowed value does not live long enough
| argument requires that `x` is borrowed for `'static`
6 | }
| - `x` dropped here while still borrowed
For more information about this error, try `rustc --explain E0597`.
Desired output
Maybe something like
hint: lifetime must be 'static to satisfy function
fn input(_: &'static str) {}
Rationale and extra context
In the example above it is also easy to figure it out yourself, but I ran into a case where the actual function is hidden:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=4c1003f809e67aec7ded5ea736ab0430
pub fn body<T: Into<Body>>(mut self, body: T) -> RequestBuilder
impl From<&'static str> for Body
In this case the message should directly point to the from implementation.
Rust Version
I tried this on the Rust playground on Rust 1.85.0