-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.D-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.Diagnostics: Confusing error or lint; hard to understand for new users.D-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.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
fn foo<T>(x: T) where &T: std::io::Read {
panic!();
}
we currently emit
error[E0637]: `&` without an explicit lifetime name cannot be used here
--> src/main.rs:1:23
|
1 | fn foo<T>(x: T) where &T: std::io::Read {
| ^ explicit lifetime name needed here
error[E0310]: the parameter type `T` may not live long enough
--> src/main.rs:1:27
|
1 | fn foo<T>(x: T) where &T: std::io::Read {
| - ^^^^^^^^^^^^^ ...so that the reference type `&'static T` does not outlive the data it points at
| |
| help: consider adding an explicit lifetime bound...: `T: 'static`
'static
suggestions are a lot of the time incorrect, but in this case what we can suggest is
fn foo<T>(x: T) where for<'a> &'a T: std::io::Read {
and both errors go away. Ideally we could silence the second error and have a structured suggestion for the first.
Taken from https://github.com/rust-lang/rust/pull/82194/files#r578364173
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.D-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.Diagnostics: Confusing error or lint; hard to understand for new users.D-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.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.