-
Notifications
You must be signed in to change notification settings - Fork 13.1k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
spurious "unused type parameter" error on struct with closure field #37249
Comments
This seems to be intentional: #23246 (comment) |
Sure, adding a struct Foo<F, S> where F: Fn(S) {
f: F,
marker: ::std::marker::PhantomData<Fn(S)>,
} but why should that be necessary? It looks redundant to me. |
This typechecks, as I would expect: struct Foo<F, T> where F: Fn() -> T {
f: F,
} Why does this succeed while my other examples fail? |
The return type is an associated type of the FnOnce trait (super of Fn). So struct Foo<I, T> where I: Iterator<Item=T> { iter: I } (unfortunately the regular trait syntax for closures is unstable, so you can't skip the type parameter and just use |
A Rust function can easily take references with different lifetimes, e.g. consider Not a bug. |
I expect the following code to typecheck:
but instead it gives the following error:
Removing
S
from the parameter list does not help:Note that there is no error if I box the closure:
The text was updated successfully, but these errors were encountered: