@@ -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,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.
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
@@ -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" : " 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 >
0 commit comments