-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-borrow-checkerArea: The borrow checkerArea: The borrow checkerA-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsD-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.Diagnostics: An error or lint that doesn't give enough information about the problem at hand.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
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
Scripter17, CorrM and workingjubilee
Metadata
Metadata
Assignees
Labels
A-borrow-checkerArea: The borrow checkerArea: The borrow checkerA-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsD-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.Diagnostics: An error or lint that doesn't give enough information about the problem at hand.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.