Skip to content
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

Merged
merged 2 commits into from
Mar 3, 2018

Conversation

Havvy
Copy link
Contributor

@Havvy Havvy commented Feb 26, 2018

No description provided.

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 +`.
Copy link
Contributor

@petrochenkov petrochenkov Feb 26, 2018

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).

Copy link
Contributor Author

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. 🙁

Copy link
Contributor

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.

@Havvy
Copy link
Contributor Author

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".

Copy link
Contributor

@matthewjasper matthewjasper left a 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
Copy link
Contributor

@matthewjasper matthewjasper Feb 27, 2018

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
Copy link
Contributor

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".

@Havvy
Copy link
Contributor Author

Havvy commented Mar 3, 2018

I've addressed the two points.

@matthewjasper matthewjasper merged commit 86b7c82 into rust-lang:master Mar 3, 2018
@matthewjasper
Copy link
Contributor

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants