-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
RFC: Bounds on trait objects should be separated with +
#87
RFC: Bounds on trait objects should be separated with +
#87
Conversation
|
||
# Detailed design | ||
|
||
Instead of `:` in trait bounds for first-class traits (e.g. `&Trait:Share + Send`), we use `+` (e.g. `&Trait + Share + Send`). |
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.
+
would be commutative, right? so &Share + Send + Trait
would also work?
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.
Yes, eventually. In the first implementation it will not.
An alternative which may want to be mentioned is to require that arguments have names or require that they don't (depending on the context). I don't believe this is the right way to go, however. |
|
||
# Drawbacks | ||
|
||
It may be that `+` is ugly. Also, it messes with the precedence of `as`. (See Rust PR #14365 for the fallout of the latter.) |
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.
Could we define as
as taking a subset of types that simply excludes Foo + Bar
? You can then use x as (Foo + Bar)
if you need that.
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.
Yes, we could bifurcate the grammar of as
; perhaps it could just take a
PATH
or a parenthesized type.
I had hoped to have |
I personally prefer @alexcrichton's alternative of requiring names. |
@sfackler Requiring names on function arguments seems potentially ok, but what about a function argument that's a closure? Requiring names on the arguments to that closure seems extreme, seeing as how every single closure function argument I've seen has skipped the names. |
Yeah, I guess that wouldn't fix this issue. |
Updated this PR to add a type grammar restriction. |
@pcwalton the more I think about it, the more I like the idea of the grammar saying something like this:
in other words, requiring parentheses around
etc |
Well, except for |
Accepted per our discussion in yesterday's meeting |
Don't store an Arc in ReadinessStream
Summary
Bounds on trait objects should be separated with
+
.Motivation
With DST there is an ambiguity between the following two forms:
and
See Rust issue #12778 for details.
Also, since kinds are now just built-in traits, it makes sense to treat a bounded trait object as just a combination of traits. This could be extended in the future to allow objects consisting of arbitrary trait combinations.
Detailed design
Instead of
:
in trait bounds for first-class traits (e.g.&Trait:Share + Send
), we use+
(e.g.&Trait + Share + Send
).Drawbacks
It may be that
+
is ugly. Also, it messes with the precedence ofas
. (See Rust PR #14365 for the fallout of the latter.)Alternatives
The impact of not doing this is that the inconsistencies and ambiguities above remain.
Unresolved questions
Where does the
'static
bound fit into all this?