Omitted names in a trait function


#1

In some languages, when the implementation is not included in the original declaration site, the original declaration is not required to include a name for every variable in the declaration, for example in c++:

class b {
    public:
    void c(int);   
};

Is there any reason that I can’t do that in a trait in rust? Or is it ‘just because’?

pub trait b{
    fn c(usize);
}

Will not compile…


#2

This was changed recently (for the 2018 edition) because the Rust team wanted it to be more clear what this variable is used for. This sort of information should be in the variable name.


#3
// This works    
pub trait b{
    fn c(_: usize);
}

I think that in edition 2018 the parameter requires a name, even if is “_”

Reference:
No more anonymous trait parameters


#4

This also came up on internals recently:


#5

It makes sense that there would be a push to make the docs and crates more readable by forcing trait function parameters names, thanks for the explanation!