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

Function overload calling syntax #1614

Closed
SoniEx2 opened this issue May 13, 2016 · 7 comments
Closed

Function overload calling syntax #1614

SoniEx2 opened this issue May 13, 2016 · 7 comments
Labels
T-lang Relevant to the language team, which will review and decide on the RFC.

Comments

@SoniEx2
Copy link

SoniEx2 commented May 13, 2016

There should be a way to call function overloads, I propose f::<T>::(argt)(argv). E.g. f::(())(()) would call a function defined as fn f(_x: ()) -> ? when you have multiple f with different args.

@oli-obk
Copy link
Contributor

oli-obk commented May 13, 2016

Rust doesn't have function overloads. So there's no need for a new syntax to call overloaded functions.

@SoniEx2
Copy link
Author

SoniEx2 commented May 13, 2016

struct Type;

impl Type {
  fn a(_x: (), _y: ()) -> () {
  }
}
impl Type {
  fn a(_x: ()) -> () {
  }
}

Come again?

@oli-obk
Copy link
Contributor

oli-obk commented May 13, 2016

That's "just a bug":

impl Type {
  fn a(_x: (), _y: ()) -> () {
  }
  fn a(_x: ()) -> () {
  }
}

errors with

duplicate associated function [E0201]

@SoniEx2
Copy link
Author

SoniEx2 commented May 13, 2016

The thing I did errors when you try to call it, but the error could be solved by adding new function call syntax that puts types into it.

@oli-obk
Copy link
Contributor

oli-obk commented May 13, 2016

The thing I did errors when you try to call it, but the error could be solved by adding new function call syntax that puts types into it.

You could already create a Overload trait and dispatch on that:

struct Type;

trait Overload<T> {
    fn a(T) -> ();
}

impl Overload<((), ())> for Type {
  fn a(args: ((), ())) -> () {
  }
}

impl Overload<((),)> for Type {
  fn a(args: ((),)) -> () {
  }
}

fn main() {
    Type::a(((),));
    Type::a(((),()));
}

@nrc nrc added the T-lang Relevant to the language team, which will review and decide on the RFC. label Aug 17, 2016
@nrc
Copy link
Member

nrc commented Aug 17, 2016

Filed rust-lang/rust#35763 for the overloaded function bug.

@Centril
Copy link
Contributor

Centril commented Oct 14, 2018

I'm skeptical that we'll ever do overloading of this sort; so therefore I'll close this to reduce clutter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-lang Relevant to the language team, which will review and decide on the RFC.
Projects
None yet
Development

No branches or pull requests

4 participants