-
Notifications
You must be signed in to change notification settings - Fork 520
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Trait object syntax + trailing plus #255
Conversation
src/types.md
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm working on adding some documentation for them soon.
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". |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. A couple of small things.
src/types.md
Outdated
`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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and ?
bounds ("opt-out bounds"?) can't be used.
src/types.md
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this would be clearer as separate sentences instead of "with the exception that".
I've addressed the two points. |
Thanks! |
No description provided.