Skip to content
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

[E0631] signature mismatch for function with Fn trait arguments with GAT arguments #88355

Closed
tim3z opened this issue Aug 26, 2021 · 1 comment

Comments

@tim3z
Copy link

tim3z commented Aug 26, 2021

Compiling this code

#![feature(generic_associated_types)]

trait Iterable {
    type Iterator<'a>;
    fn iter(&self) -> Self::Iterator<'_>;
}

struct SomeImplementation();

impl Iterable for SomeImplementation {
    type Iterator<'a> = std::iter::Empty<usize>;
    fn iter(&self) -> Self::Iterator<'_> {
        std::iter::empty()
    }
}

fn do_something<I: Iterable>(i: I, mut f: impl for<'a> Fn(&mut I::Iterator<'a>)) {
    f(&mut i.iter());
}

fn main() {
    do_something(SomeImplementation(), |_| ());
    do_something(SomeImplementation(), test);
}

fn test<'a, I: Iterable>(_: &mut I::Iterator<'a>) {}

with the current nightly (rustc 1.56.0-nightly (0afc20860 2021-08-25)) yields an E0631 argument mismatch for both calls to do_something.

error[E0631]: type mismatch in closure arguments
  --> src/main.rs:22:5
   |
22 |     do_something(SomeImplementation(), |_| ());
   |     ^^^^^^^^^^^^                       ------ found signature of `for<'r> fn(&'r mut std::iter::Empty<usize>) -> _`
   |     |
   |     expected signature of `for<'r, 'a> fn(&'r mut <SomeImplementation as Iterable>::Iterator<'a>) -> _`
   |
note: required by a bound in `do_something`
  --> src/main.rs:17:48
   |
17 | fn do_something<I: Iterable>(i: I, mut f: impl for<'a> Fn(&mut I::Iterator<'a>)) {
   |                                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `do_something`

error[E0631]: type mismatch in function arguments
  --> src/main.rs:23:40
   |
23 |     do_something(SomeImplementation(), test);
   |                                        ^^^^ expected signature of `for<'a> fn(&mut <SomeImplementation as Iterable>::Iterator<'a>) -> _`
...
26 | fn test<'a, I: Iterable>(_: &mut I::Iterator<'a>) {}
   | ------------------------------------------------- found signature of `for<'r> fn(&'r mut std::iter::Empty<usize>) -> _`
   |
note: required by a bound in `do_something`
  --> src/main.rs:17:56
   |
17 | fn do_something<I: Iterable>(i: I, mut f: impl for<'a> Fn(&mut I::Iterator<'a>)) {
   |                                                        ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `do_something`

I expected both calls to compile and from looking at the errors I also see no reasons why the signatures should be incompatible. In the case that my expectation is wrong I would expect the compiler to give me some hint, why this is not possible.

@tim3z
Copy link
Author

tim3z commented Aug 27, 2021

Superceded by #88382

@tim3z tim3z closed this as completed Aug 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant