-
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
#92917 breaks type inference on GATs #93874
Comments
Ah yeah, you also now have to make an existential type to name every unnameable type (e.g. types containing closures) if they go through a GAT (have to use #![feature(generic_associated_types)]
#![feature(type_alias_impl_trait)]
pub trait Build {
type Output<O>;
fn build<O>(self, input: O) -> Self::Output<O>;
}
pub struct IdentityBuild;
impl Build for IdentityBuild {
type Output<O> = O;
fn build<O>(self, input: O) -> Self::Output<O> {
input
}
}
fn x() {
let mut f = IdentityBuild.build(|| ());
(f)();
// ^type annotations needed
// type must be known at this pointrustcE0282
// main.rs(17, 9): consider giving `x` a type
}
fn y() {
type MyFn = impl FnOnce();
let f: MyFn = IdentityBuild.build(|| ());
(f)();
// Compiles
}
pub fn main() {
x();
} |
I think this probably can be solved by normalizing somewhere where we aren't now; there aren't inference variables here.
This, I'm not sure about, since we do have an inference variable. Still, I think we can normalize still and end up with the |
Does #93361 fix this? |
You know what? It actually doesn't, sorry, should've checked first before I brought it up as a possibility. The first error gets reported as The second error ends up happening because of an ambiguity error during selection. I can look more into why that's failing. |
So the second error is ambiguous because that type variable can't be proved |
Seems to be caused by #92917 @jackh726
So this regression seems to be intentional, but I want to make sure because even very basic inference fails now, making any use of GATs very fill up with explicit type annotations. It doesn't look so bad in this example, but with complex types it's bad, and I think there's a more complex example the compiler can't even tell what
_x
is at all, but I'm still working on that.Code
I expected to see this happen: compiles without error
Instead, this happened: Type inference fails,
Output<O> = O
seems to be ignored or not understood by the compiler.Version it worked on
It most recently worked on:
Version with regression
rustc --version --verbose
:Backtrace
(no crash)
The text was updated successfully, but these errors were encountered: