-
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
Using associated types in async fn type break typing #60414
Comments
cc #50547 |
You can trigger this without async/await using struct Foo<T>(T);
trait FooLike { type Output; }
impl<T> FooLike for Foo<T> {
type Output = T;
}
trait Trait {
type Assoc;
}
fn foo<T: Trait<Assoc = ()>>() -> impl FooLike<Output = T::Assoc> {
Foo(())
}
|
Some more reduction in genericity and clearing up a few things: #![feature(impl_trait_in_bindings)]
struct Foo;
trait FooLike { type Output; }
impl FooLike for Foo {
type Output = u32;
}
trait Trait {
type Assoc;
}
fn foo<T: Trait<Assoc = i32>>() {
let _: impl FooLike<Output = T::Assoc> = Foo;
}
The problem is that |
It seems to be a missing normalization, most likely. |
This also happens for #![feature(existential_type)]
trait Implemented {
type Assoc;
}
impl<T> Implemented for T {
type Assoc = u8;
}
trait Trait {
type Out;
}
impl Trait for () {
type Out = u8;
}
existential type Ex: Trait<Out = <() as Implemented>::Assoc>;
fn define() -> Ex {
()
}
My fix only seems to turn this into a cycle error for some reason. EDIT: Nevermind I just broke existential types in general lol |
Marking as blocking, although I think there's minimal future compat risk. If push came to shove I personally would be ok with removing this from the blocking list. But then it looks like @jonas-schievink already fixed it =) |
@jonas-schievink I think the problem is on this line of code: rust/src/librustc/infer/opaque_types/mod.rs Line 344 in 8301de1
in particular, we "instantiate" the predicates -- meaning, substitute in the values for their type parameters -- but we never normalize them. We should be able to invoke the self.infcx.partially_normalize_associated_types_in(span, body-id, param_env, &predicates) this returns an |
@nikomatsakis Hmm, that code is only invoked if I also noticed that However, another place where rust/src/librustc/infer/opaque_types/mod.rs Line 1039 in 088b987
...and there |
@jonas-schievink good catch -- actually I think the lines you found are the ones I meant to direct you to in the first place. I see you have some other problems on the PR, looking now. |
…tsakis Normalize projections appearing in `impl Trait` Fixes #60414 This does not try to do the same for `existential type`s (which have the same bug), since that always seems to lead to cycle errors.
With the following code:
comes the following error:
(playground link)
However, this function compiles correctly without the
async
keyword.The text was updated successfully, but these errors were encountered: