-
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
FnOnce with GAT argument with HRTB is misinterpreted by the type system #107572
Comments
So the short story is that the lifetime I agree the diagnostic really is misleading though. |
Why does normalizing introduce issues? Let's consider another but very similar example: trait GAT {
// > < added a bound
type Assoc<'a>: 'a;
}
fn foo<A: GAT>(f: impl for<'a> FnOnce(<A as GAT>::Assoc<'a>) -> <A as GAT>::Assoc<'a>) {} And now the error still persists. However from the standpoint of Another way to think about it is that GATs resemble type constructors and if we consider However what about variance in GATs? I don't think |
@compiler-errors hmm, so you're saying that it's okay but just an error is misleading? If so is it even possible at all then to declare a function with such intent, i.e. accepting rank-2 labmda that has an argument of whatever lifetime and returns it? |
But both the argument and the return type will be normalized to the same type? So if the normalized type references the lifetime then the input flows into the output, or it doesn't, and then there is no issue? |
Looks like a duplicate of #86702 My understanding of the issue is that the compiler is being overly conservative when reasoning about whether a lifetime can appear in the generic parameters and/or associated types of a trait bound (for To fix this I think it should reason about the relations between those types, and simple equality is not enough (see the second example in this comment of mine) |
Issue #32330 mentions desugaring, and the primary reason seems to relate to the fact that closure types can only ever be parameterless in their desugared form in their current implementation. It's also why generic closures aren't supported, as far as I understand. |
The issue in #32330 was only due to lifetimes only appearing in the output type/associated type. In the case of this issue this is impossible, since if the lifetime appear in the output then it will also have to appear in the input (and The problem is that the current logic for preventing the bug described in #32330 is overly conservative and assumes that projections in input types never contain lifetimes, while projections in output types always contain lifetimes, which obviously fails when the input and output types are the same (or at least somehow related) |
While it's true, the lifetimes in GATs aren't ever considered used (and for a good reason: they don't have to be used at all!), and this would also exclude more general cases such as [1] The less general case only considers |
But the issue is about higher ranked trait bounds, whose lifetimes can't be named by the bounded type, thus you can't move them to the closure type. |
Edit: unfortunately adding a lifetime to a type wouldn't really work, I've just realized. Accounting for a lifetime use in associated type still can unless I'm missing something. |
I tried this code:
And it fails to compile:
Even if it's not a bug, but the current type system limitations, the error description E0582 seems to be misleading(or is not well descriptive).
Meta
Checked with rustc:
The text was updated successfully, but these errors were encountered: