@@ -5,9 +5,9 @@ trait, written in type positions) but this was a bit too confusing, so we now
5
5
write ` dyn Trait ` .
6
6
7
7
Some 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 ]
9
9
traits. 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.
11
11
12
12
Two general aspects of trait object types give rise to the restrictions:
13
13
@@ -34,7 +34,7 @@ aspects.
34
34
### The trait requires ` Self: Sized `
35
35
36
36
Traits 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.
38
38
39
39
The reasoning behind this is somewhat subtle. It derives from the fact that Rust
40
40
requires (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
61
61
to the rule that ` dyn Trait ` always implements ` Trait ` , Rust chooses to prohibit
62
62
such a ` dyn Trait ` from existing at all.
63
63
64
- Only unsized traits are considered dyn- compatible.
64
+ Only unsized traits are considered dyn compatible.
65
65
66
66
Generally, ` Self: Sized ` is used to indicate that the trait should not be used
67
67
as a trait object. If the trait comes from your own crate, consider removing
@@ -106,7 +106,7 @@ fn call_foo(x: Box<dyn Trait>) {
106
106
}
107
107
```
108
108
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 `
110
110
bound on them to mark them as explicitly unavailable to trait objects. The
111
111
functionality will still be available to all other implementers, including
112
112
` Box<dyn Trait> ` which is itself sized (assuming you `impl Trait for Box<dyn
@@ -120,7 +120,7 @@ trait Trait {
120
120
```
121
121
122
122
Now, ` 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
124
124
methods. With such a bound, one can still call ` foo() ` on types implementing
125
125
that trait that aren't behind trait objects.
126
126
@@ -309,7 +309,7 @@ Here, the supertrait might have methods as follows:
309
309
310
310
```
311
311
trait 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!
313
313
}
314
314
```
315
315
@@ -318,8 +318,8 @@ If the trait `Trait` was deriving from something like `Super<String>` or
318
318
` get_a() ` will definitely return an object of that type.
319
319
320
320
However, 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
323
323
no longer compatible, so they are forbidden when specifying supertraits.
324
324
325
325
There's no easy fix for this. Generally, code will need to be refactored so that
0 commit comments