Skip to content

Commit 7ae8780

Browse files
committed
Rename "object safe" to "dyn compatible"
1 parent 23ce619 commit 7ae8780

File tree

4 files changed

+56
-23
lines changed

4 files changed

+56
-23
lines changed

Diff for: src/glossary.md

+22-6
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,14 @@ the hierarchy has its own collection of named entities.
173173
### Nominal types
174174

175175
Types that can be referred to by a path directly. Specifically [enums],
176-
[structs], [unions], and [trait objects].
176+
[structs], [unions], and [trait object types].
177177

178-
### Object safe traits
178+
### Dyn-compatible 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 [trait object types] (`dyn Trait`).
181+
Only traits that follow specific [rules][dyn compatibility] are *dyn compatible*.
182+
183+
These were formerly known as *object safe* traits.
182184

183185
### Path
184186

@@ -293,6 +295,7 @@ example of an uninhabited type is the [never type] `!`, or an enum with no varia
293295
[attributes]: attributes.md
294296
[*entity*]: names.md
295297
[crate]: crates-and-source-files.md
298+
[dyn compatibility]: items/traits.md#dyn-compatibility
296299
[enums]: items/enumerations.md
297300
[fields]: expressions/field-expr.md
298301
[free item]: #free-item
@@ -315,12 +318,11 @@ example of an uninhabited type is the [never type] `!`, or an enum with no varia
315318
[*name*]: names.md
316319
[*namespace*]: names/namespaces.md
317320
[never type]: types/never.md
318-
[object safety]: items/traits.md#object-safety
319321
[*path*]: paths.md
320322
[Paths]: paths.md
321323
[*scope*]: names/scopes.md
322324
[structs]: items/structs.md
323-
[trait objects]: types/trait-object.md
325+
[trait object types]: types/trait-object.md
324326
[traits]: items/traits.md
325327
[turbofish test]: https://github.com/rust-lang/rust/blob/1.58.0/src/test/ui/parser/bastion-of-the-turbofish.rs
326328
[types of crates]: linkage.md
@@ -329,3 +331,17 @@ example of an uninhabited type is the [never type] `!`, or an enum with no varia
329331
[unions]: items/unions.md
330332
[variable bindings]: patterns.md
331333
[visibility rules]: visibility-and-privacy.md
334+
335+
<script>
336+
(function() {
337+
var fragments = {
338+
"#object-safe-traits": "glossary.html#dyn-compatible-traits",
339+
};
340+
var target = fragments[window.location.hash];
341+
if (target) {
342+
var url = window.location.toString();
343+
var base = url.substring(0, url.lastIndexOf('/'));
344+
window.location.replace(base + "/" + target);
345+
}
346+
})();
347+
</script>

Diff for: src/items/traits.md

+30-13
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Trait functions are not allowed to be [`const`].
5252

5353
Generic items may use traits as [bounds] on their type parameters.
5454

55-
## Generic Traits
55+
## Generic traits
5656

5757
Type parameters can be specified for a trait to make it generic. These appear
5858
after the trait name, using the same syntax used in [generic functions].
@@ -65,12 +65,12 @@ trait Seq<T> {
6565
}
6666
```
6767

68-
## Object Safety
68+
## Dyn compatibility
6969

70-
Object safe traits can be the base trait of a [trait object]. A trait is
71-
*object safe* if it has the following qualities (defined in [RFC 255]):
70+
A dyn-compatible trait can be the base trait of a [trait object]. A trait is
71+
*dyn compatible* if it has the following qualities:
7272

73-
* All [supertraits] must also be object safe.
73+
* All [supertraits] must also be dyn compatible.
7474
* `Sized` must not be a [supertrait][supertraits]. In other words, it must not require `Self: Sized`.
7575
* It must not have any associated constants.
7676
* It must not have any associated types with generics.
@@ -92,11 +92,14 @@ Object safe traits can be the base trait of a [trait object]. A trait is
9292
* Explicitly non-dispatchable functions require:
9393
* Have a `where Self: Sized` bound (receiver type of `Self` (i.e. `self`) implies this).
9494

95+
This concept was formerly known as *object safety*.
96+
The original set of rules was defined in [RFC 255] and has since been extended.
97+
9598
```rust
9699
# use std::rc::Rc;
97100
# use std::sync::Arc;
98101
# use std::pin::Pin;
99-
// Examples of object safe methods.
102+
// Examples of dyn compatible methods.
100103
trait TraitMethods {
101104
fn by_ref(self: &Self) {}
102105
fn by_ref_mut(self: &mut Self) {}
@@ -113,7 +116,7 @@ trait TraitMethods {
113116
```
114117

115118
```rust,compile_fail
116-
// This trait is object-safe, but these methods cannot be dispatched on a trait object.
119+
// This trait is dyn compatible, but these methods cannot be dispatched on a trait object.
117120
trait NonDispatchable {
118121
// Non-methods cannot be dispatched.
119122
fn foo() where Self: Sized {}
@@ -137,8 +140,8 @@ obj.typed(1); // ERROR: cannot call with generic type
137140

138141
```rust,compile_fail
139142
# use std::rc::Rc;
140-
// Examples of non-object safe traits.
141-
trait NotObjectSafe {
143+
// Examples of dyn-incompatible traits.
144+
trait DynIncompatible {
142145
const CONST: i32 = 1; // ERROR: cannot have associated const
143146
144147
fn foo() {} // ERROR: associated function without Sized
@@ -148,14 +151,14 @@ trait NotObjectSafe {
148151
}
149152
150153
struct S;
151-
impl NotObjectSafe for S {
154+
impl DynIncompatible for S {
152155
fn returns(&self) -> Self { S }
153156
}
154-
let obj: Box<dyn NotObjectSafe> = Box::new(S); // ERROR
157+
let obj: Box<dyn DynIncompatible> = Box::new(S); // ERROR
155158
```
156159

157160
```rust,compile_fail
158-
// Self: Sized traits are not object-safe.
161+
// `Self: Sized` traits are dyn-incompatible.
159162
trait TraitWithSize where Self: Sized {}
160163
161164
struct S;
@@ -164,7 +167,7 @@ let obj: Box<dyn TraitWithSize> = Box::new(S); // ERROR
164167
```
165168

166169
```rust,compile_fail
167-
// Not object safe if `Self` is a type argument.
170+
// Dyn-incompatible if `Self` is a type argument.
168171
trait Super<A> {}
169172
trait WithSelf: Super<Self> where Self: Sized {}
170173
@@ -349,3 +352,17 @@ fn main() {
349352
[`async`]: functions.md#async-functions
350353
[`const`]: functions.md#const-functions
351354
[type namespace]: ../names/namespaces.md
355+
356+
<script>
357+
(function() {
358+
var fragments = {
359+
"#object-safety": "items/traits.html#dyn-compatibility",
360+
};
361+
var target = fragments[window.location.hash];
362+
if (target) {
363+
var url = window.location.toString();
364+
var base = url.substring(0, url.lastIndexOf('/'));
365+
window.location.replace(base + "/" + target);
366+
}
367+
})();
368+
</script>

Diff for: src/type-coercions.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ r[coerce.unsize.slice]
209209
* `[T; n]` to `[T]`.
210210

211211
r[coerce.unsize.trait-object]
212-
* `T` to `dyn U`, when `T` implements `U + Sized`, and `U` is [object safe].
212+
* `T` to `dyn U`, when `T` implements `U + Sized`, and `U` is [dyn compatible].
213213

214214
r[coerce.unsized.composite]
215215
* `Foo<..., T, ...>` to `Foo<..., U, ...>`, when:
@@ -322,7 +322,7 @@ precisely.
322322
[RFC 401]: https://github.com/rust-lang/rfcs/blob/master/text/0401-coercions.md
323323
[RFC 1558]: https://github.com/rust-lang/rfcs/blob/master/text/1558-closure-to-fn-coercion.md
324324
[subtype]: subtyping.md
325-
[object safe]: items/traits.md#object-safety
325+
[dyn compatible]: items/traits.md#dyn-compatibility
326326
[type cast operator]: expressions/operator-expr.md#type-cast-expressions
327327
[`Unsize`]: std::marker::Unsize
328328
[`CoerceUnsized`]: std::ops::CoerceUnsized

Diff for: src/types/trait-object.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ r[type.trait-object.syntax]
1212
1313
r[type.trait-object.intro]
1414
A *trait object* is an opaque value of another type that implements a set of
15-
traits. The set of traits is made up of an [object safe] *base trait* plus any
15+
traits. The set of traits is made up of a [dyn compatible] *base trait* plus any
1616
number of [auto traits].
1717

1818
r[type.trait-object.impls]
@@ -116,6 +116,6 @@ inferred with a sensible choice.
116116
[_TypeParamBounds_]: ../trait-bounds.md
117117
[auto traits]: ../special-types-and-traits.md#auto-traits
118118
[defaults]: ../lifetime-elision.md#default-trait-object-lifetimes
119+
[dyn compatible]: ../items/traits.md#dyn-compatibility
119120
[dynamically sized types]: ../dynamically-sized-types.md
120-
[object safe]: ../items/traits.md#object-safety
121121
[supertraits]: ../items/traits.md#supertraits

0 commit comments

Comments
 (0)