# Justification for Rust not Supporting Function Overloading (directly)

**URL:** <https://internals.rust-lang.org/t/justification-for-rust-not-supporting-function-overloading-directly/7012>\
**Category:** Uncategorized\
**Created:** [March 10, 2018, 7:46pm UTC](https://internals.rust-lang.org/t/justification-for-rust-not-supporting-function-overloading-directly/7012 "2018-03-10T19:46:03Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![scottmcm](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/scottmcm/32/2355_2.png) [@scottmcm](https://internals.rust-lang.org/u/scottmcm)\
**Post date:** [March 10, 2018, 11:19pm UTC](https://internals.rust-lang.org/t/justification-for-rust-not-supporting-function-overloading-directly/7012/3 "2018-03-10T23:19:28Z")

</div>

There probably isn’t much about it explicitly, because it’s a direct consequence of a different design choice: the desire to not have monomorphization-time errors in generics.

Take a function like this:

```rust
fn foo<T>(x: T) { bar(x) }

```

Today, that’s easy:

- the call to `bar` is to the `bar` that’s in-scope at the definition of `foo`
- `bar` must be a function that accepts anything, since `T` is unbounded

Imagine overloading existed. Both would be way harder:

- Which `bar` are we calling? Is it the `bar` in-scope right now? If there are two in-scope right now, which of them? An overload of `bar` that doesn’t exist yet? A `bar` [in the same module where the concrete generic argument is defined](https://en.wikipedia.org/wiki/Argument-dependent_name_lookup)?
- When is `foo` even valid? Is it “whenever there’s a `bar` somewhere that happens to match what we need”? Do we need to like all the types for which `bar` exists in the bound somewhere?

Explicitly indirecting through the trait, rather than having everything be a potential indirection point, makes everything was easier, both to understand what’s happening and to implement.

---

_[View the full topic](https://internals.rust-lang.org/t/justification-for-rust-not-supporting-function-overloading-directly/7012)._
