reference icon indicating copy to clipboard operation
reference copied to clipboard

Reword "object safety" as "trait-object safety"

Open kornelski opened this issue 1 year ago • 5 comments

"Object safe" is not a self-explanatory term.

The the word "object" doesn't have a clear definition in Rust's context, and to users it may not be obvious that the term refers to trait objects specifically.

The "safe" part is not good either, because it could be misunderstood as relating to "safe Rust" or not-unsafe.

However, the term "object safe" is used in a lot of places, so I propose a minimal backwards-compatible fix by calling this concept "trait-object safety". Addition of the word "trait" adds context, and clearly connects it to trait objects.

Users may only know this concept from Box<dyn Trait> types, so I'm also emphasising dyn Trait compatibility.

More in the forum thread: https://internals.rust-lang.org/t/object-safety-is-a-terrible-term/21025

kornelski avatar Jun 16 '24 15:06 kornelski

It's odd that the link checker doesn't get the right anchor, even tough when I run mdbook build locally, it writes the correct one. It seems like {#anchor} syntax isn't always supported?

kornelski avatar Jun 18 '24 16:06 kornelski

To support heading attributes, the version of mdbook in https://github.com/rust-lang/reference/blob/0b805c65804019b0ac8f2fe3117afad82a6069b8/.github/workflows/main.yml#L22 needs to be updated to the latest version (0.4.40).

ehuss avatar Jun 18 '24 17:06 ehuss

We discussed this in a rustdocs call. We're going to let the discussion on IRLO play out a bit further, then we may lang nominate this.

traviscross avatar Jun 18 '24 21:06 traviscross

However, the term "object safe" is used in a lot of places, so I propose a minimal backwards-compatible fix by calling this concept "trait-object safety".

We've definitely been using the term "object safe" or "object safety" for a long time in many places, so we don't want to leave people unable to look up that term. But I don't think that means we need to leave the term substantially unmodified; I think that means we need to leave plenty of pointers to what we used to call it.

I would suggest, instead, that we fully rebrand this as "dyn Trait compatible" (or, when appropriate, "compatible with dyn Trait" or "dyn-compatible"), and then include notes saying things like "This is sometimes also called 'trait-object safety', 'object safety', or 'object safe'." With that, plus keeping the old link anchors working (though we should add new ones as well to avoid making the old ones look like the canonical names), I think that'll be sufficient to not abandon people who already know the existing term.

joshtriplett avatar Jun 20 '24 16:06 joshtriplett

@rustbot labels -S-waiting-on-team

When this ongoing FCP completes, we will have decided to call traits that are compatible with dyn "dyn compatible" rather than "object safe".

traviscross avatar Sep 25 '24 07:09 traviscross

@rustbot author

traviscross avatar Oct 22 '24 21:10 traviscross

Competing PR: #1666.

fmease avatar Oct 28 '24 16:10 fmease

Closing in favor of #1666.

ehuss avatar Oct 30 '24 13:10 ehuss