Skip to content

Fns with different arguments should be different types #34868

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

Closed
jethrogb opened this issue Jul 16, 2016 · 3 comments
Closed

Fns with different arguments should be different types #34868

jethrogb opened this issue Jul 16, 2016 · 3 comments

Comments

@jethrogb
Copy link
Contributor

jethrogb commented Jul 16, 2016

Currently you can't write something like this:

pub trait MyTrait {
}

impl<F> MyTrait for F where F: FnMut() {
}

impl<F> MyTrait for F where F: FnMut(usize) -> usize {
}

This results in an error about conflicting implementations. This is because there might exist a type that implements both FnMut() and FnMut(usize) -> usize. In reality such a type will of course never exist.

Potential dupe of #19032 but I'm not sure

@TimNN
Copy link
Contributor

TimNN commented Jul 16, 2016

Actually, I'm pretty sure that it is easily possible for a type to implement both, since the Fn traits can be implememted for a type like any other traits, ie. you can do struct A; impl Fn() for A { ... }.

@nagisa
Copy link
Member

nagisa commented Jul 17, 2016

Once implementing Fn-traits is made stable, what @TimNN said is correct. Such case could also occur once we get something like default arguments, resulting in one value having multiple ways to call it – and thus multiple FnOnce implementations.

This issue is likely inactionable.

@arielb1
Copy link
Contributor

arielb1 commented Jul 17, 2016

Yea. Not a bug. Implementing FnOnce with different input types is intentionally allowed.

@arielb1 arielb1 closed this as completed Jul 17, 2016
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants