Skip to content

Commit 554c4c1

Browse files
authored
Merge pull request #2 from durka/patch-10
fix object safety section
2 parents 5d0b4fe + 8a72471 commit 554c4c1

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

text/0000-trait-alias.md

+11-7
Original file line numberDiff line numberDiff line change
@@ -133,23 +133,27 @@ parameter declarations*.
133133

134134
When using a trait alias as an object type, it is subject to object safety restrictions _after_ substituting the aliased traits. This means:
135135

136-
1. It contains an object safe trait and zero or more of these other bounds: `Send`, `Sync`, `'static` (that is, `trait Show = Display + Debug;` would not be object safe).
136+
1. It contains an object safe trait, optionally a lifetime, and zero or more of these other bounds: `Send`, `Sync` (that is, `trait Show = Display + Debug;` would not be object safe).
137137
2. All the associated types of the trait need to be specified.
138+
3. The `where` clause, if present, only contains bounds on `Self`.
138139

139140
Some examples:
140141

141142
```rust
142143
trait Sink = Sync;
143-
trait PrintableIterator = Display + Iterator;
144+
trait ShareableIterator = Iterator + Sync;
145+
trait PrintableIterator = Iterator<Item=i32> + Display;
144146
trait IntIterator = Iterator<Item=i32>;
145147

146-
fn foo<T: PrintableIterator>(...) { ... } // ok
147-
fn baz1(x: Box<PrintableIterator>) { ... } // ERROR: associated type not specified
148-
fn baz2(x: Box<PrintableIterator<Item=i32>>) { ... } // ok
149-
fn baz3(x: Box<IntIterator + Sink + 'static>) { ... } // ok (*)
148+
fn foo1<T: ShareableIterator>(...) { ... } // ok
149+
fn foo2<T: ShareableIterator<Item=i32>>(...) { ... } // ok
150+
fn bar1(x: Box<ShareableIterator>) { ... } // ERROR: associated type not specified
151+
fn bar2(x: Box<ShareableIterator<Item=i32>>) { ... } // ok
152+
fn bar3(x: Box<PrintableIterator>) { ... } // ERROR: too many traits (*)
153+
fn bar4(x: Box<IntIterator + Sink + 'static>) { ... } // ok (*)
150154
```
151155

152-
The lines marked with `(*)` require [#24010](https://github.com/rust-lang/rust/issues/24010) to be fixed.
156+
The lines marked with `(*)` assume that [#24010](https://github.com/rust-lang/rust/issues/24010) is fixed.
153157

154158
# Drawbacks
155159
[drawbacks]: #drawbacks

0 commit comments

Comments
 (0)