Uh oh!
There was an error while loading. Please reload this page.
Trait object syntax + trailing plus - #255
Conversation
| of auto traits followed optionally by a lifetime bound all separated by and | ||
| optionally terminated by `+`. For example, given a trait `Trait`, the following | ||
| are all trait objects: `Trait`, `Trait + Send`, `Trait + Send + Sync`, | ||
| `Trait + 'static`, `Trait + Send + 'static`, `Trait +`. |
There was a problem hiding this comment.
'static + Send + Trait also works.
In general, trait objects have exactly the same syntax as bounds after T in fn f<T: BOUNDS>() { ... }, it would be great to unify them in the reference as well.
Trait objects just have some additional semantic restrictions (n(lifetimes) <=1, n(non-auto-traits) <=1).
There was a problem hiding this comment.
'static + Send + Trait explicitly doesn't work giving me error[E0225]: only auto traits can be used as additional traits in a trait object. 'static + Trait does work.
Generic bounds don't seem to be in the reference at all right now. 🙁
There was a problem hiding this comment.
I'm working on adding some documentation for them soon.
Havvy
commented
Feb 26, 2018
Added lifetimes to the grammar and said they are written the same as trait bounds. @matthewjasper Feel free to move the grammar over to describing type bounds when you get to it, and then change the grammar for trait objects to just be "TypeBounds". |
matthewjasper
left a comment
There was a problem hiding this comment.
Looks good. A couple of small things.
| `Trait + Send + 'static`. | ||
| Trait objects are written the same as trait bounds with the exception that all | ||
| traits except the first trait must be auto traits and there may not be more than | ||
| one lifetime. For example, given a trait `Trait`, the following |
There was a problem hiding this comment.
and ? bounds ("opt-out bounds"?) can't be used.
| example, given a trait `Trait`, the following are all trait objects: `Trait`, | ||
| `Trait + Send`, `Trait + Send + Sync`, `Trait + 'static`, | ||
| `Trait + Send + 'static`. | ||
| Trait objects are written the same as trait bounds with the exception that all |
There was a problem hiding this comment.
I think this would be clearer as separate sentences instead of "with the exception that".
Havvy
commented
Mar 3, 2018
I've addressed the two points. |
matthewjasper
commented
Mar 3, 2018
Thanks! |
No description provided.