@@ -52,7 +52,7 @@ Trait functions are not allowed to be [`const`].
5252
5353Generic items may use traits as [ bounds] on their type parameters.
5454
55- ## Generic Traits
55+ ## Generic traits
5656
5757Type parameters can be specified for a trait to make it generic. These appear
5858after the trait name, using the same syntax used in [ generic functions] .
@@ -65,12 +65,13 @@ trait Seq<T> {
6565}
6666```
6767
68- ## Object Safety
68+ <a id =" object-safety " ></a >
69+ ## Dyn compatibility
6970
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 ] ) :
71+ A dyn-compatible trait can be the base trait of a [ trait object] . A trait is
72+ * dyn compatible * if it has the following qualities:
7273
73- * All [ supertraits] must also be object safe .
74+ * All [ supertraits] must also be dyn compatible .
7475* ` Sized ` must not be a [ supertrait] [ supertraits ] . In other words, it must not require ` Self: Sized ` .
7576* It must not have any associated constants.
7677* It must not have any associated types with generics.
@@ -92,11 +93,13 @@ Object safe traits can be the base trait of a [trait object]. A trait is
9293 * Explicitly non-dispatchable functions require:
9394 * Have a ` where Self: Sized ` bound (receiver type of ` Self ` (i.e. ` self ` ) implies this).
9495
96+ > ** Note** : This concept was formerly known as * object safety* .
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.
100103trait 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.
117120trait 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
150153struct 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 .
159162trait TraitWithSize where Self: Sized {}
160163
161164struct 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.
168171trait Super<A> {}
169172trait WithSelf: Super<Self> where Self: Sized {}
170173
@@ -330,7 +333,6 @@ fn main() {
330333[ _WhereClause_ ] : generics.md#where-clauses
331334[ bounds ] : ../trait-bounds.md
332335[ trait object ] : ../types/trait-object.md
333- [ RFC 255 ] : https://github.com/rust-lang/rfcs/blob/master/text/0255-object-safety.md
334336[ associated items ] : associated-items.md
335337[ method ] : associated-items.md#methods
336338[ supertraits ] : #supertraits
@@ -349,3 +351,17 @@ fn main() {
349351[ `async` ] : functions.md#async-functions
350352[ `const` ] : functions.md#const-functions
351353[ type namespace ] : ../names/namespaces.md
354+
355+ <script >
356+ (function () {
357+ var fragments = {
358+ " #object-safety" : " traits.html#dyn-compatibility" ,
359+ };
360+ var target = fragments[window .location .hash ];
361+ if (target) {
362+ var url = window .location .toString ();
363+ var base = url .substring (0 , url .lastIndexOf (' /' ));
364+ window .location .replace (base + " /" + target);
365+ }
366+ })();
367+ </script >
0 commit comments