@@ -5,9 +5,9 @@ trait, written in type positions) but this was a bit too confusing, so we now
55write ` dyn Trait ` .
66
77Some traits are not allowed to be used as trait object types. The traits that
8- are allowed to be used as trait object types are called "dyn- compatible"[ ^ 1 ]
8+ are allowed to be used as trait object types are called "dyn compatible"[ ^ 1 ]
99traits. Attempting to use a trait object type for a trait that is not
10- dyn- compatible will trigger error E0038.
10+ dyn compatible will trigger error E0038.
1111
1212Two general aspects of trait object types give rise to the restrictions:
1313
@@ -34,7 +34,7 @@ aspects.
3434### The trait requires ` Self: Sized `
3535
3636Traits that are declared as ` Trait: Sized ` or which otherwise inherit a
37- constraint of ` Self:Sized ` are not dyn- compatible.
37+ constraint of ` Self:Sized ` are not dyn compatible.
3838
3939The reasoning behind this is somewhat subtle. It derives from the fact that Rust
4040requires (and defines) that every trait object type ` dyn Trait ` automatically
@@ -61,7 +61,7 @@ implement a sized trait like `Trait:Sized`. So, rather than allow an exception
6161to the rule that ` dyn Trait ` always implements ` Trait ` , Rust chooses to prohibit
6262such a ` dyn Trait ` from existing at all.
6363
64- Only unsized traits are considered dyn- compatible.
64+ Only unsized traits are considered dyn compatible.
6565
6666Generally, ` Self: Sized ` is used to indicate that the trait should not be used
6767as a trait object. If the trait comes from your own crate, consider removing
@@ -106,7 +106,7 @@ fn call_foo(x: Box<dyn Trait>) {
106106}
107107```
108108
109- If only some methods aren't dyn- compatible, you can add a ` where Self: Sized `
109+ If only some methods aren't dyn compatible, you can add a ` where Self: Sized `
110110bound on them to mark them as explicitly unavailable to trait objects. The
111111functionality will still be available to all other implementers, including
112112` Box<dyn Trait> ` which is itself sized (assuming you `impl Trait for Box<dyn
@@ -120,7 +120,7 @@ trait Trait {
120120```
121121
122122Now, ` foo() ` can no longer be called on a trait object, but you will now be
123- allowed to make a trait object, and that will be able to call any dyn- compatible
123+ allowed to make a trait object, and that will be able to call any dyn compatible
124124methods. With such a bound, one can still call ` foo() ` on types implementing
125125that trait that aren't behind trait objects.
126126
@@ -309,7 +309,7 @@ Here, the supertrait might have methods as follows:
309309
310310```
311311trait Super<A: ?Sized> {
312- fn get_a(&self) -> &A; // note that this is dyn- compatible!
312+ fn get_a(&self) -> &A; // note that this is dyn compatible!
313313}
314314```
315315
@@ -318,8 +318,8 @@ If the trait `Trait` was deriving from something like `Super<String>` or
318318` get_a() ` will definitely return an object of that type.
319319
320320However, if it derives from ` Super<Self> ` , even though ` Super ` is
321- dyn- compatible, the method ` get_a() ` would return an object of unknown type when
322- called on the function. ` Self ` type parameters let us make dyn- compatible traits
321+ dyn compatible, the method ` get_a() ` would return an object of unknown type when
322+ called on the function. ` Self ` type parameters let us make dyn compatible traits
323323no longer compatible, so they are forbidden when specifying supertraits.
324324
325325There's no easy fix for this. Generally, code will need to be refactored so that
0 commit comments