-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Existential types: Unused closure environment is part of concrete type #57678
Comments
I'm confident this is a duplicate of #42940, but let's wait for others to confirm. |
This isn't a duplicate of that issue-- the error message here is "correct" in a sense. The issue here is that the closure being generated is still generic over type parameters, even when they're unused. We don't have any logic today (AFAIK) for detecting when a type parameter goes unused in a closure, so by default they capture all generic parameters in scope. Desugaring the argument-position #![feature(existential_type)]
existential type T: ;
fn test<A>() -> T {
|| {}
}
The fix here is to detect when a type parameter is unused in a closure and make it so that the closure is no longer generic over that parameter. I remember talking with @nikomatsakis about this in the past and I think they indicated that this was hard to do in the current system. |
That would indeed be quite hard to do. For one thing, the set of generics is determined quite early on -- this would require us to wait until we see what the closure does. But also, it's non-trivial to figure out when the type parameter was important to the closure. |
I guess I'll close this for now as "working as intended", though it'd definitely be nice to drop unnecessary type parameters from closures anyways (for codegen purposes). |
Compare
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=194cca6bdb23ec0b634bc01dea43abd4
which results in
error: type parameter `impl Copy` is part of concrete type but not used in parameter list for existential type
tohttps://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=23789461920ea49d85042a9604f86f97
which compiles fine.
There are quite a few open issues for existential types so I hope I haven't overlooked a duplicate. #42940 might be related.
Meta
The text was updated successfully, but these errors were encountered: