What is the reason for not having overloaded versions of fn?

Could you please explain to me why it was decided not to have overloaded versions. Instead I have to name function silly, like:

fn new()->Self
fn new_with_name()->Self
fn new_with_name_and_something_else()->Self

Or perhaps, do you think that it would be a something that Rust could benefit from?

1 Like

A quick search brings up e. g. this thread with some answers

1 Like

The simple answer is that no one has ever put together a solid enough proposal that ended up getting accepted. As far as I'm aware overloading has never been explicitly ruled out by the lang team.

1 Like

Overloading is known for causing issues with type inference and human-readability. (It's not an accident it's called "ad-hoc polymorphism" by type theorists.) In Rust, everything that overloading is useful for can be done by means of traits and generics in a much more regular, easier-to-reason-about manner.


I won't speak as to readability, but at least with regard to inference allowing one function definition for any given number of arguments wouldn't cause an issue. I know it's something I've wanted in a few niche cases. Not full-on overloading, but still quite useful.

Could you please link to some reliable source that would substantiate what you are claiming and stating as a fact?

1 Like

This was posted on urlo and probably belongs there anyway: What is the reason for not having overloaded versions of fn? - #3 by dupdrop - The Rust Programming Language Forum

@piter76 please don't post duplicate threads like this on both urlo and irlo.