Closed
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
Area: Messages for errors, warnings, and lintsArea: Lifetimes / regionsArea: Suggestions generated by the compiler applied by `cargo fix`Category: An issue proposing an enhancement or a PR with one.Diagnostics: A structured suggestion resulting in incorrect code.Diagnostics: Confusing error or lint; hard to understand for new users.Diagnostics: An error or lint that needs small tweaks.Relevant to the compiler team, which will review and decide on the PR/issue.