diff --git a/src/doc/reference.md b/src/doc/reference.md index 9c0538e6a3c7..3d7d6bf6961c 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -3603,6 +3603,45 @@ fn main() { In this example, the trait `Printable` occurs as a trait object in both the type signature of `print`, and the cast expression in `main`. +Trait objects may contain references, and so those references will need a +lifetime: + +```rust,ignore +// Some trait like this... +trait Bar<'a>: 'a { } + +// ... means these are the same: +Box +Box +``` + +If there’s no bound, then the default lifetime is the same as the pointer that +the trait object is behind: + +```rust,ignore +// Some trait like this... +trait Bar { } + +// ... means these are the same: +&'a Bar +&'a (Bar + 'a) +``` + +In any other case, the default is `'static`: + +```rust,ignore +// Some trait like this... +trait Bar { } + +// ... means these are the same: +Box +Box + +// and so are these: +&'a Box +&'a Box +``` + ### Type parameters Within the body of an item that has type parameter declarations, the names of