Rust Function Overloading - Call for Experimentation

Aug. 19, 2026 · teor on behalf of The Language Team

In partnership with the Rust Foundation's Rust-C++ Interop Initiative, the Rust Project has been experimenting with function overloading for FFI bindings. This experiment is now at a stage where compiler and interop tool developers can start exploring function overloading.

Stable Rust already supports a form of overloading using tuples and traits, but calling these overloaded functions looks strange, because the overloaded arguments have to be passed as a single tuple argument, like this: hypot((2.0, 3.0, 6.0)). Stable Rust also allows overloading of built-in operators with user-defined types, via traits like Add (the + operator) and Neg (the - value negation operator).

We are running an unstable nightly Rust language experiment to answer questions like:

  • How much overloading can we do with Rust’s existing trait system?
  • Could this help us call C++ from Rust ergonomically?

In the tradition of yeet (to avoid bikeshedding), we are using basic syntax in the first stage of the experiment: the #[rustc_splat] attribute. Alternative syntaxes can be considered later, if the experiment generates useful outcomes.

Experimental Function Overloading

Rust nightly builds from 2026-07-31 onwards have experimental support for more ergonomic function and method overloading, using the incomplete "splat" compiler feature; if you're a compiler or interop tool developer, we encourage you to experiment with it!

This experiment lets overloaded functions be called with separate arguments, like this: hypot(2.0, 3.0, 6.0). No double parentheses required! But type inference and type checking still happen as they would in a stable Rust overload.

We are experimenting with splat to get a feel for the complexity of the implementation, and to see if it solves some language interoperability use cases. Like most Rust language experiments, this nightly feature has no RFC, and can change or be removed at any time.

Experiment Design

We expect the feature to change significantly in future, or to be replaced by a more ergonomic interface. In this spirit, Ajay Singh, a Rust Project Outreachy intern, is working on a macro to make splat-based overloading more ergonomic. You can find his work in the rust-foundation/overloading-macros repository on GitHub.

The design axioms for this feature are:

  • "keep Rust nice"
  • make calling overloaded FFI functions easy
  • preserve foreign language maintainability
  • select the overload most developers would expect

This could be a challenging design, because different programming languages have different overload resolution rules.

Example Usage

Rust overloading aims to support a range of programming languages. This example uses C++ because it is well known, and has significant existing interop tooling.

Here is some Rust code that calls the overloaded C++ hypot (hypotenuse) function, using "splat" to create corresponding overloads in Rust.

#![feature(splat, tuple_trait)]
#![expect(incomplete_features)]

use cpp::cpp;
use std::{ffi::c_double, marker::Tuple};

cpp! {{ #include <cmath> }}

/// The arguments of an overloaded C++ `hypot` function.
trait HypotArgs: Tuple {
    type Output;
    fn call_hypot(self) -> Self::Output;
}

/// Calls the overloaded C++ `std::hypot` function with the given arguments.
fn hypot<Args: HypotArgs>(#[rustc_splat] args: Args) -> <Args as HypotArgs>::Output {
    args.call_hypot()
}

/// A 2-argument `hypot` overload.
impl HypotArgs for (c_double, c_double) {
    type Output = c_double;
    fn call_hypot(self) -> c_double {
        let (x, y) = self;
        unsafe {
            cpp!([x as "double", y as "double"] -> c_double as "double" {
                // This is C++ code!
                return std::hypot(x, y);
            })
        }
    }
}

/// A 3-argument `hypot` overload.
impl HypotArgs for (c_double, c_double, c_double) {
    type Output = c_double;
    fn call_hypot(self) -> c_double {
        let (x, y, z) = self;
        unsafe {
            cpp!([x as "double", y as "double", z as "double"] -> c_double as "double" {
                return std::hypot(x, y, z);
            })
        }
    }
}

fn main() {
    println!("|(3, 4)|    = {}", hypot(3.0, 4.0));
    println!("|(2, 3, 6)| = {}", hypot(2.0, 3.0, 6.0));
}

This example uses the cpp crate to inline C++ code in a Rust file. A full runnable example is available on GitHub. You can also run a minimal Rust-only example online, in the Rust playground.

Nadrieril’s original "Overloading at Home" code from his recent write-up of "splat", can also be run in the Rust playground.

Limitations

As stated above, splat is currently an incomplete compiler feature, and is only available in the nightly Rust compiler. Splat is also unergonomic, and we want to change that as part of the next design phase.

Support for splatted function arguments in rustdoc just merged on 12 August. Splatted arguments display as an ellipsis (…), rather than the argument name. This syntax is unstable, currently only used for display in rustdoc, and can change at any time. For example:

fn example(#[rustc_splat] args: (u32, String));

Is displayed as:

fn example(…: (u32, String));

We've also recently merged splat support for function pointers, if you're seeing an internal compiler error, please update to the latest nightly. If you want overloading support for function pointers, please let us know about your use case in the #t-lang/interop channel on Zulip.

And there is an ongoing Rust standard library experiment using splat for variable-argument smallest and greatest functions. Hopefully they will be available soon on nightly.

Experimenters will find other bugs – some have already been found in the last few months – and some overloading functionality is out of scope for now. If you think you've found a bug or limitation, ask us about it in the #t-lang/interop channel on Zulip.

Credits

This work would not be possible without Google’s generous funding and support of the Rust Foundation’s Rust-C++ Interop Initiative.

It is driven by the Nightly support for function overloading in FFI bindings Rust Project goal, and it is an outcome of the C++/Rust Interop Problem Space Mapping Rust Project goal.

Thank you also to everyone who has contributed to the overloading work, including Oli, Ajay, Nadrieril, Scott, Taylor, Tyler, Matthias, Tim, Devin, Ralf, Jacob, Zachary and the many project members who have given suggestions, feedback, testing, bug reports, and reviews.

Future Work

Overloading, In The Shiny Future

#[overload]
impl f64 {
    /// Returns the 2-dimensional distance from the origin.
    fn hypot(self, y: f64) -> f64 { … }

    /// Returns the 3-dimensional distance from the origin.
    fn hypot(self, y: f64, z: f64) -> f64 { … }
}

(This example is a variant of a design shared by Taylor Cramer.)

In the shiny future, Rust might have an #[overload] attribute that "just works" to call overloaded foreign functions with the same name. No traits, tuples, or #[rustc_splat] required, the compiler handles it all for you. Since this work is targeted at interop, overloading might be limited to extern blocks to start with. Extending it to native Rust could be a separate feature, stabilised on a longer timeframe (or not at all).

This might happen through macros that hide compiler implementation internals, or it might not need any macros. It's hard to guess what the final shape of the feature will be: we’ve only just started the first experiment.

Future Designs

We have a lot of work to do before we can discuss overloading designs in detail. The "splat" experiment will help us find the limits of the Rust type system, how it handles typical foreign language overloads, the diagnostics needed to guide overloading users, and any design gaps for future work.

We’ll also need to find a syntax for overloading, if it is accepted. Naming things is hard, as many users of function overloading have discovered 😅

Stay tuned for future interop updates on our blog. You can see the full list of Project Goals here, many of which are working towards better interop with a range of programming languages.