Allow redundant `pub fn` in traits

Could pub be allowed in trait definitions and implementations?

trait Foo {
    pub fn foo();
}

impl Foo for Bar {
    pub fn foo() {}
}

I know it’s unnecessary/redundant, but when I copy/move functions between concrete impl and traits, I need to remember to add or remove it accordingly.

It feels like a warning/style nitpick that’s unnecessarily a hard error (E0449).

2 Likes

I’d be worried about cases that mixed pub and non pub functions in the same trait implementation; people might mistakenly think private functions are allowed in trait impls as helpers or the like.

Also, this seems like an error that an IDE could suggest or automatically carry out for the user; as of Rust 1.18 there is no valid case for pub fn in a trait impl, so the IDE could provide easy removal. Tooling shouldn’t be used as an excuse for poor ergonomics, but in this case it would leave the committed code in a more readable state not having the ambiguity.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.