-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
E0582 on valid HRTB code #49601
Comments
Seconded. Found this issue via #70262 |
I'm running into the same issue with GAT (playground): #![feature(generic_associated_types)]
pub trait Trait {
type Gat<'a>;
}
fn fun<T, U, F>()
where
T: Trait,
U: Trait,
F: for<'a> FnOnce(T::Gat<'a>) -> U::Gat<'a>,
{
} What's the way forward here? |
This error was introduced as a fix for #32330. It seems to intentionally ignore projection inputs: rust/src/librustc_middle/ty/fold.rs Lines 966 to 990 in d903a9d
The reasoning there makes sense to me. Allowing this would potentially (depending on the There is also this test that makes sure that this is rejected, which matches the code in the original report almost exactly: rust/src/test/ui/associated-types/bound-lifetime-constrained.rs Lines 37 to 41 in d903a9d
However, @nikomatsakis wrote in #32330:
Is this still accurate, and has there been any movement on this? Would it allow the code posted here to compile? It looks like the work on universes (#56105) may be part of the solution here. Since the example in the original report can be simply made to compile by making |
Hmm. To be honest, I don't think this has much to do with the early- vs late-bound region distinction, or maybe it's just to far out of cache. Things like It is definitely true that the On the other hand, this is not obviously a problem to me. Quite possibly that where clause would not be provable, so the fn likely couldn't be called, but it might be that the function itself could ultimately be type-checked successfully. To be honest thought I wouldn't expect to make many changes here for the moment. It doesn't seem like a major pattern or enabler to me and I'd be happier waiting until we make more progress in transitioning to chalk or at least improving other aspects of rustc's trait solver (which we are starting to do in order to enable GATs). |
I think these can be worked around with helper traits. (None of the examples have examples of application to test against though.) pub trait Helper<Other>: IntoIterator<Item=<Self as Helper<Other>>::Item> {
type Item: MyTrait<T = Other>;
}
impl<U, Other> Helper<Other> for U where U: IntoIterator, U::Item: MyTrait<T = Other> {
type Item = <Self as IntoIterator>::Item;
}
pub fn foo<T>(_: T)
where
for<'x> &'x T: Helper<&'x i32>
{} pub trait Helper<I, X>: FnOnce(I) -> <Self as Helper<I, X>>::Intermediate {
type Intermediate: Iterator<Item=X>;
}
impl<F, I, O, X> Helper<I, X> for F where F: FnOnce(I) -> O, O: Iterator<Item=X> {
type Intermediate = O;
}
pub fn foo<F>(_f: F) where for<'a> F: Helper<&'a i32, &'a i64> {} pub trait Helper<G, H>: FnOnce(G) -> H {}
impl<T, G, H> Helper<G, H> for T where T: FnOnce(G) -> H {}
pub fn fun<T, U, F>()
where
T: Trait,
U: Trait,
F: for<'a> Helper<T::Gat<'a>, U::Gat<'a>>,
{} See also this URLO thread. |
The compiler rejects this code with E0582.
The code is obviously valid.
The text was updated successfully, but these errors were encountered: