-
Notifications
You must be signed in to change notification settings - Fork 487
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reword "object safety" as "dyn compatibility" #1512
Conversation
or dyn Trait compatible
It's odd that the link checker doesn't get the right anchor, even tough when I run |
To support heading attributes, the version of mdbook in reference/.github/workflows/main.yml Line 22 in 0b805c6
|
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. |
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 " |
@rustbot labels -S-waiting-on-team When this ongoing FCP completes, we will have decided to call traits that are compatible with |
@@ -175,10 +175,13 @@ the hierarchy has its own collection of named entities. | |||
Types that can be referred to by a path directly. Specifically [enums], | |||
[structs], [unions], and [trait objects]. | |||
|
|||
### Object safe traits | |||
### Trait-object-safe traits |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
### Trait-object-safe traits | |
### Dyn-compatible traits |
[Traits] that can be used in `dyn Trait` types, and allow creation of | ||
[trait objects]. Only traits that follow specific [rules][object safety] are | ||
trait-object safe. | ||
|
||
This is also called *object safety*. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Traits] that can be used in `dyn Trait` types, and allow creation of | |
[trait objects]. Only traits that follow specific [rules][object safety] are | |
trait-object safe. | |
This is also called *object safety*. | |
[Traits] that can be used in [trait object types][trait objects] (`dyn Trait`). Only traits that follow specific [rules][dyn-compatibility] are dyn compatible. | |
Formerly known as *object safety*. |
+ updating the second part of the reference-style MarkDown link.
TC, let me know if you agree with my suggestion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks about right. Probably worth making a full sentence out of the last line, e.g. "These were formerly known as object safe traits".
@@ -62,12 +62,12 @@ trait Seq<T> { | |||
} | |||
``` | |||
|
|||
## Object Safety | |||
## Trait-Object Safety <a id="object-safety"></a> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
## Trait-Object Safety <a id="object-safety"></a> | |
## Dyn Compatibility |
NB: I'd love the URL fragment (named anchor) to get changed to dyn-compatibility
and have an HTTP redirect from object-safety
. Although I haven't checked if the Reference is set up to support redirects. I know that the rustc-dev-guide is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add a paragraph or footnote pointing out that this concept is "formerly known as object safety".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NB: I'd love the URL fragment (named anchor) to get changed to dyn-compatibility and have an HTTP redirect from object-safety
This would be quite nice because we show this URL literally in rustc's diagnostics. As a result of that we currently have a mismatch of terminology on nightly (diagnostic text vs. URL). Of course, that's expected but I'd like this to be temporary only (namely until this PR hits stable (rustc's diagnostics usually link to the stable channel of the Reference)) as it's a bit awkward imho.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When renaming sections, you need to use a <script>
tag to redirect the fragment, see
reference/src/expressions/operator-expr.md
Lines 687 to 699 in c64e52a
<script> | |
(function() { | |
var fragments = { | |
"#slice-dst-pointer-to-pointer-cast": "operator-expr.html#pointer-to-pointer-cast", | |
}; | |
var target = fragments[window.location.hash]; | |
if (target) { | |
var url = window.location.toString(); | |
var base = url.substring(0, url.lastIndexOf('/')); | |
window.location.replace(base + "/" + target); | |
} | |
})(); | |
</script> |
@@ -93,7 +93,7 @@ Object safe traits can be the base trait of a [trait object]. A trait is | |||
# use std::rc::Rc; | |||
# use std::sync::Arc; | |||
# use std::pin::Pin; | |||
// Examples of object safe methods. | |||
// Examples of trait-object safe methods. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Examples of trait-object safe methods. | |
// Examples of dyn-compatible methods. |
Though strictly speaking we haven't defined "dyn compatible" for methods, only for traits. We could be more explicit but not sure if worthwhile.
An object-safe trait can be used in a `dyn Trait` type, and be the base trait of a [trait object]. | ||
A trait is *object safe* if it has the following qualities (defined in [RFC 255]): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An object-safe trait can be used in a `dyn Trait` type, and be the base trait of a [trait object]. | |
A trait is *object safe* if it has the following qualities (defined in [RFC 255]): | |
A dyn-compatible trait can be used in a trait object type (`dyn Trait`), and be the base trait of a [trait object]. | |
A trait is *dyn compatible* if it has the following qualities (defined in [RFC 255]): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated to the renaming: The dyn-compatibility rules have been updated over time (for example, "dyn-incompatible" associated types marked with where Self: Sized
no longer render the trait dyn-incompatible). So stating that the rules were defined in RFC 255 is misleading or at the very least outdated. That should probably be changed as part of a separate PR though.
@@ -110,7 +110,7 @@ trait TraitMethods { | |||
``` | |||
|
|||
```rust,compile_fail | |||
// This trait is object-safe, but these methods cannot be dispatched on a trait object. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should double-check if there are any other mentions of /(non[\- _]?)?obj(ect)?[\- _](un)?safe(ty)?/i
and update them accordingly.
@@ -135,7 +135,7 @@ obj.typed(1); // ERROR: cannot call with generic type | |||
```rust,compile_fail | |||
# use std::rc::Rc; | |||
// Examples of non-object safe traits. | |||
trait NotObjectSafe { | |||
trait NotDynCompatible { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
trait NotDynCompatible { | |
trait DynIncompatible { |
+ usage sites
@@ -135,7 +135,7 @@ obj.typed(1); // ERROR: cannot call with generic type | |||
```rust,compile_fail | |||
# use std::rc::Rc; | |||
// Examples of non-object safe traits. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Examples of non-object safe traits. | |
// Examples of dyn-incompatible traits. |
+ all other occurrences of this phrasing in this repo.
@@ -7,8 +7,8 @@ | |||
> _TraitObjectTypeOneBound_ :\ | |||
> `dyn`<sup>?</sup> [_TraitBound_] | |||
|
|||
A *trait object* is an opaque value of another type that implements a set of | |||
traits. The set of traits is made up of an [object safe] *base trait* plus any | |||
A *trait object* is an opaque value of a `dyn`-prefixed type that implements a set of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor nitpick, can ignore: Describing types (semantic layer) via a 'syntactic characteristic' doesn't sit quite right with me. Esp. since this specific characteristic isn't the whole truth (cc existence of bare trait object types in earlier editions).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update analogously
@rustbot author |
Competing PR: #1666. |
Closing in favor of #1666. |
"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 emphasisingdyn Trait
compatibility.More in the forum thread:
https://internals.rust-lang.org/t/object-safety-is-a-terrible-term/21025