Default type parameter not inferred: is it a bug?


#1

Hi,

I just started using Rust this week. I’m coming from C++ and C# and Rust seems to do so many things better.

I tried to compile this program, but I get an error saying it can’t infer the type:

use std::ops::*;

fn asd<T, T2 = f32>(x: T, y: T) -> T::Output
    where T : Add
{
    x + y
}

fn main()
{
    asd(1, 2);
}

src/main.rs:15:5: 15:8 error: unable to infer enough type information about `_`; type annotations or generic parameter binding required [E0282]
src/main.rs:15     asd(1, 2);
                   ^~~

I’ve specified the default for T2, so I think it should compile fine.
What am I doing wrong?


#2

Nothing (except that T2 is currently useless). This hasn’t been fully implemented: https://github.com/rust-lang/rust/issues/21939


#3

It’s a coming feature.


#4

https://github.com/rust-lang/rust/pull/26870 suggests that it works on nightly when using #![feature(default_type_parameter_fallback)].


#5

Okey, thanks.

I just made a simple example, it’s not indended to do anything useful.