-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
E0581/E0582 (lifetime not found in input type) occurs even when the lifetime is in traits used as inputs #86702
Comments
A workaround to this bug is to just add an |
Sadly, it's not "used" in the specific sense that And the important thing is that not only the generic form (still parameterized by As far as I was trying to find some history on this, and there's a RFC (0447) but I remember these things being a huge soundness hole - there's issues like #32330 and more recently #47470, but they don't link together nicely. Anyway, I'd probably let @nikomatsakis handle this, but I'd either close this as "working as intended", or turn it into a diagnostic issue, in that we could special-case the error to not sound wrong. Specifically, "which does not appear in the trait input types" is not technically correct (the lifetime appears but is unconstrained by the type it appears in). |
Yeah I definitely think this situation should have a diagnostic that at a minimum talks about the soundness issue and perhaps proposes the workaround. |
Is there any change to make this more permissible when it can be proven that if the normalized output type contains a lifetime then one of the input types must also contain it? For example I would expect the following snippet to compile because the input and output types are the same, so there's no way only the return type contains a lifetime after normalization: trait A<'a> {
type Assoc;
}
fn test<T, F>(_: F)
where
T: for<'a> A<'a>,
F: for<'a> FnOnce(<T as A<'a>>::Assoc) -> <T as A<'a>>::Assoc
{} This is a more complicated example, but I would also expect it to compile because if trait A<'a> {
type AssocA: B;
}
trait B {
type AssocB;
}
fn test<T, F>(_: F)
where
T: for<'a> A<'a>,
F: for<'a> FnOnce(<T as A<'a>>::AssocA) -> <<T as A<'a>>::AssocA as B>::AssocB
{} |
(playpen, also tested on
rustc 1.54.0-nightly (fe72845f7 2021-05-16)
)produces
The lifetime is used in the inputs, just behind a trait.
The text was updated successfully, but these errors were encountered: