Skip to content

Commit ccb0d6d

Browse files
committed
Reword object safety as trait-object safety
or dyn Trait compatible
1 parent 0b805c6 commit ccb0d6d

File tree

4 files changed

+23
-20
lines changed

4 files changed

+23
-20
lines changed

src/glossary.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,13 @@ the hierarchy has its own collection of named entities.
175175
Types that can be referred to by a path directly. Specifically [enums],
176176
[structs], [unions], and [trait objects].
177177

178-
### Object safe traits
178+
### Trait-object-safe traits
179179

180-
[Traits] that can be used as [trait objects]. Only traits that follow specific
181-
[rules][object safety] are object safe.
180+
[Traits] that can be used in `dyn Trait` types, and allow creation of
181+
[trait objects]. Only traits that follow specific [rules][object safety] are
182+
trait-object safe.
183+
184+
This is also called *object safety*.
182185

183186
### Path
184187

src/items/traits.md

+12-12
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ trait Seq<T> {
6262
}
6363
```
6464

65-
## Object Safety
65+
## Trait-Object Safety {#object-safety}
6666

67-
Object safe traits can be the base trait of a [trait object]. A trait is
68-
*object safe* if it has the following qualities (defined in [RFC 255]):
67+
An object-safe trait can be used in a `dyn Trait` type, and be the base trait of a [trait object].
68+
A trait is *object safe* if it has the following qualities (defined in [RFC 255]):
6969

70-
* All [supertraits] must also be object safe.
70+
* All [supertraits] must also be trait-object safe.
7171
* `Sized` must not be a [supertrait][supertraits]. In other words, it must not require `Self: Sized`.
7272
* It must not have any associated constants.
7373
* It must not have any associated types with generics.
@@ -93,7 +93,7 @@ Object safe traits can be the base trait of a [trait object]. A trait is
9393
# use std::rc::Rc;
9494
# use std::sync::Arc;
9595
# use std::pin::Pin;
96-
// Examples of object safe methods.
96+
// Examples of trait-object safe methods.
9797
trait TraitMethods {
9898
fn by_ref(self: &Self) {}
9999
fn by_ref_mut(self: &mut Self) {}
@@ -110,7 +110,7 @@ trait TraitMethods {
110110
```
111111

112112
```rust,compile_fail
113-
// This trait is object-safe, but these methods cannot be dispatched on a trait object.
113+
// This trait is object-safe, but these methods cannot be dispatched on a trait object (such as `&dyn NonDispatchable`).
114114
trait NonDispatchable {
115115
// Non-methods cannot be dispatched.
116116
fn foo() where Self: Sized {}
@@ -135,7 +135,7 @@ obj.typed(1); // ERROR: cannot call with generic type
135135
```rust,compile_fail
136136
# use std::rc::Rc;
137137
// Examples of non-object safe traits.
138-
trait NotObjectSafe {
138+
trait NotDynCompatible {
139139
const CONST: i32 = 1; // ERROR: cannot have associated const
140140
141141
fn foo() {} // ERROR: associated function without Sized
@@ -145,14 +145,14 @@ trait NotObjectSafe {
145145
}
146146
147147
struct S;
148-
impl NotObjectSafe for S {
148+
impl NotDynCompatible for S {
149149
fn returns(&self) -> Self { S }
150150
}
151-
let obj: Box<dyn NotObjectSafe> = Box::new(S); // ERROR
151+
let obj: Box<dyn NotDynCompatible> = Box::new(S); // ERROR
152152
```
153153

154154
```rust,compile_fail
155-
// Self: Sized traits are not object-safe.
155+
// Self: Sized traits are not trait-object-safe.
156156
trait TraitWithSize where Self: Sized {}
157157
158158
struct S;
@@ -161,7 +161,7 @@ let obj: Box<dyn TraitWithSize> = Box::new(S); // ERROR
161161
```
162162

163163
```rust,compile_fail
164-
// Not object safe if `Self` is a type argument.
164+
// Not trait-object safe if `Self` is a type argument.
165165
trait Super<A> {}
166166
trait WithSelf: Super<Self> where Self: Sized {}
167167
@@ -326,7 +326,7 @@ fn main() {
326326
[_Visibility_]: ../visibility-and-privacy.md
327327
[_WhereClause_]: generics.md#where-clauses
328328
[bounds]: ../trait-bounds.md
329-
[trait object]: ../types/trait-object.md
329+
[trait objects]: ../types/trait-object.md
330330
[RFC 255]: https://github.com/rust-lang/rfcs/blob/master/text/0255-object-safety.md
331331
[associated items]: associated-items.md
332332
[method]: associated-items.md#methods

src/type-coercions.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ an implementation of `Unsize<U>` for `T` will be provided:
170170

171171
* `[T; n]` to `[T]`.
172172

173-
* `T` to `dyn U`, when `T` implements `U + Sized`, and `U` is [object safe].
173+
* `T` to `dyn U`, when `T` implements `U + Sized`, and `U` is [trait-object safe].
174174

175175
* `Foo<..., T, ...>` to `Foo<..., U, ...>`, when:
176176
* `Foo` is a struct.
@@ -269,7 +269,7 @@ precisely.
269269
[RFC 401]: https://github.com/rust-lang/rfcs/blob/master/text/0401-coercions.md
270270
[RFC 1558]: https://github.com/rust-lang/rfcs/blob/master/text/1558-closure-to-fn-coercion.md
271271
[subtype]: subtyping.md
272-
[object safe]: items/traits.md#object-safety
272+
[trait-object safe]: items/traits.md#object-safety
273273
[type cast operator]: expressions/operator-expr.md#type-cast-expressions
274274
[`Unsize`]: ../std/marker/trait.Unsize.html
275275
[`CoerceUnsized`]: ../std/ops/trait.CoerceUnsized.html

src/types/trait-object.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
> _TraitObjectTypeOneBound_ :\
88
> &nbsp;&nbsp; `dyn`<sup>?</sup> [_TraitBound_]
99
10-
A *trait object* is an opaque value of another type that implements a set of
11-
traits. The set of traits is made up of an [object safe] *base trait* plus any
10+
A *trait object* is an opaque value of a `dyn`-prefixed type that implements a set of
11+
traits. The set of traits is made up of a [trait-object safe] *base trait* plus any
1212
number of [auto traits].
1313

1414
Trait objects implement the base trait, its auto traits, and any [supertraits]
@@ -103,5 +103,5 @@ inferred with a sensible choice.
103103
[auto traits]: ../special-types-and-traits.md#auto-traits
104104
[defaults]: ../lifetime-elision.md#default-trait-object-lifetimes
105105
[dynamically sized types]: ../dynamically-sized-types.md
106-
[object safe]: ../items/traits.md#object-safety
106+
[trait-object safe]: ../items/traits.md#object-safety
107107
[supertraits]: ../items/traits.md#supertraits

0 commit comments

Comments
 (0)