Login
You're viewing the techdon.dev public feed.
  • Jul 7, 2026, 3:32 AM

    #Rust users! How would you feel about a language change in the next edition where trait items were private by default, requiring an explicit `pub` to make functions, consts, and types in traits part of the API?

    Existing editions would be unchanged, always having trait items be public.

    I'm trying to gauge public sentiment on changing the default.

    #RustLang

    💬 2🔄 0⭐ 0

Replies

  • Jul 7, 2026, 3:36 AM

    A migration lint would be provided, but changing the default would necessarily mean large diffs as every pre-existing trait item would have `pub` added to it. My argument in favor is primarily consistency, while others have argued against it on the basis that `pub` is by far the most common (which I do not dispute).

    💬 0🔄 0⭐ 0
  • Jul 7, 2026, 4:01 AM

    @jhpratt it's been a long day so maybe I'm missing the obvious, but what would it actually mean for a trait item to not be pub?

    💬 1🔄 0⭐ 0
  • Jul 7, 2026, 4:03 AM

    @megmac It could neither be implemented nor called downstream. If a trait item without a default body (or type/const) were not visible in a given scope, you'd be unable to implement the trait as a result. Just as constructing a struct with private fields isn't permitted.

    💬 0🔄 0⭐ 0
  • Jul 7, 2026, 7:38 AM

    @jhpratt I kind of want to vote against this because pub is going to be, by far, the dominant choice and it just seems silly (Java-y even) to force it to be said on everything, but i have a visceral reaction to the indirectness of `pub(self)` (like, it reads as "public... PSYCH!") that is making me second guess that.

    💬 0🔄 0⭐ 0