Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upEarly trait bounds on generic types #590
Conversation
nrc
assigned
aturon
Jan 22, 2015
This comment has been minimized.
This comment has been minimized.
|
@Kimundi Thanks for this RFC, and sorry to be slow commenting on it. I quite like this idea, and I think you've very carefully thought out the tradeoffs and nuances for rolling out; I'm basically happy to take the RFC as-is. I would note that this has some interaction with implies bounds, though it's not clear if/when we'll get those. But essentially, that change would put even more pressure to follow the convention you're laying out here. |
This comment has been minimized.
This comment has been minimized.
|
rust-lang/rust#23176 is related: it (unfortunately) "removes" the motivating example, by making |
huonw
referenced this pull request
Mar 8, 2015
Merged
Remove unneeded Send/Sync bounds on Arc, Mutex, RwLock and sync::mpsc #23176
pnkfelix
referenced this pull request
Mar 21, 2015
Closed
stdlib is instantiating `Arc<T>` with T's that are not `Send+Sync` #23584
aturon
added
the
T-libs
label
May 22, 2015
This comment has been minimized.
This comment has been minimized.
|
One thing that was not clear to me: the RFC mentions adding these bounds after the fact, but that would be a breaking change -- I presume we intend to follow this only for newer types, if we accept it now? |
This comment has been minimized.
This comment has been minimized.
|
Arguably hoisting "universal" requirements to the struct level is a minor breaking change in that:
|
This comment has been minimized.
This comment has been minimized.
|
On the RFC as a whole, I feel like this could largely be alleviated by better error message tooling overall. Right now we have a nasty habit of telling you the "last detail" of why your code is wrong. e.g. in this case we're telling you you're calling a non-existent method, where really this is just a consequence of missing the bound. I'm not familiar enough with the error-reporting tooling, but it seems plausible in theory to "explore" the type's impl's for matching names and construct plausible causes. See also rust-lang/rust#21793 |
This comment has been minimized.
This comment has been minimized.
|
Note: This RFC entered its Final Comment Period as of yesterday. |
alexcrichton
added
the
final-comment-period
label
May 27, 2015
This comment has been minimized.
This comment has been minimized.
|
This RFC does seem to unfortunately contradict the decision made in rust-lang/rust#23176, the rationale there being that operating generically over these types is much easier if the bounds are not required (as sometimes they may not be, for example deriving). I think that the motivation here was also solved by that PR by only using the Also, 1.0 has been released since this RFC was written, so I would personally prefer to take the opposite route of adding bounds to type definitions as soon as possible. Bounds should only be required when absolutely necessary, for example |
This comment has been minimized.
This comment has been minimized.
|
Yeah, with the new stance to have impls be as minimal as possible this RFC is largely obsoleted |
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis: Ah, just re-read your comment. Such a change is indeed a breaking change after-the-fact, this should ideally have been a pre-1.0 thing... Though Gankro's comment also holds true. |
This comment has been minimized.
This comment has been minimized.
bluss
commented
May 30, 2015
|
I think it's annoying to implement types this way, and by extension use them this way. Ironically (to me), trait bounds on a struct don't help you, because instead of being the default for any use of the struct, they simply become mandatory to repeat for any use of it. In a way, you lose when you give the compiler more information. I prefer the minimal route. Usually bounds on the struct definition is only required for A) Correspondance with Drop B) Using associated types in fields. The |
This comment has been minimized.
This comment has been minimized.
BlacklightShining
commented
May 30, 2015
|
@alexcrichton I don't see that decision as being relevant here. As @huonw said there,
In contrast, some types like |
This comment has been minimized.
This comment has been minimized.
This happens to be the same reason why |
This comment has been minimized.
This comment has been minimized.
|
The state of the standard library has definitely changed since this RFC was first opened, and the specific motivation listed has since been fixed. The policy in the standard library for now will likely be "do not mention bounds in datatype definitions unless the compiler requires it", but this is perhaps subject to change over time. Regardless, however, existing APIs cannot be altered due to backwards compatibility concerns, so I'm going to close this RFC now. Thanks regardless though for it @Kimundi! |
Kimundi commentedJan 17, 2015
Summary
Make it an API convention that generic types that have an interface
that always requires the same trait bounds on the same type parameters
should have those bounds directly in the type definition. Allow exceptions
from this rule for cases like planned changes or upholding backwards
compatibility.
Rendered