@@ -2103,7 +2103,7 @@ a `&T` pointer. `MutexArc` is an example of a *sharable* type with internal muta
2103
2103
These are types that do not contain any data whose lifetime is bound to
2104
2104
a particular stack frame. These are types that do not contain any
2105
2105
references, or types where the only contained references
2106
- have the `'static` lifetime. (For more on named lifetimes and their uses,
2106
+ have the `'static` lifetime. (For more on named lifetimes and their uses,
2107
2107
see the [references and lifetimes guide][lifetimes].)
2108
2108
2109
2109
> ***Note:*** These two traits were referred to as 'kinds' in earlier
@@ -2430,23 +2430,25 @@ select the method to call at runtime.
2430
2430
2431
2431
This usage of traits is similar to Java interfaces.
2432
2432
2433
- By default, each of the three storage classes for traits enforce a
2434
- particular set of built-in kinds that their contents must fulfill in
2435
- order to be packaged up in a trait object of that storage class .
2433
+ There are some built-in bounds, such as `Send` and `Share`, which are properties
2434
+ of the components of types. By design, trait objects don't know the exact type
2435
+ of their contents and so the compiler cannot reason about those properties .
2436
2436
2437
- * The contents of owned traits (`~Trait`) must fulfill the `Send` bound.
2438
- * The contents of reference traits (`&Trait`) are not constrained by any bound.
2437
+ You can instruct the compiler, however, that the contents of a trait object must
2438
+ acribe to a particular bound with a trailing colon (`:`). These are examples of
2439
+ valid types:
2439
2440
2440
- Consequently, the trait objects themselves automatically fulfill their
2441
- respective kind bounds. However, this default behavior can be overridden by
2442
- specifying a list of bounds on the trait type, for example, by writing `~Trait:`
2443
- (which indicates that the contents of the owned trait need not fulfill any
2444
- bounds), or by writing `~Trait:Send+Share`, which indicates that in addition
2445
- to fulfilling `Send`, contents must also fulfill `Share`, and as a consequence,
2446
- the trait itself fulfills `Share`.
2441
+ ~~~rust
2442
+ trait Foo {}
2443
+ trait Bar<T> {}
2447
2444
2448
- * `~Trait:Send` is equivalent to `~Trait`.
2449
- * `&Trait:` is equivalent to `&Trait`.
2445
+ fn sendable_foo(f: ~Foo:Send) { /* ... */ }
2446
+ fn shareable_bar<T: Share>(b: &Bar<T>: Share) { /* ... */ }
2447
+ ~~~
2448
+
2449
+ When no colon is specified (such as the type ` ~Foo ` ), it is inferred that the
2450
+ value ascribes to no bounds. They must be added manually if any bounds are
2451
+ necessary for usage.
2450
2452
2451
2453
Builtin kind bounds can also be specified on closure types in the same way (for
2452
2454
example, by writing ` fn:Send() ` ), and the default behaviours are the same as
0 commit comments