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 upRFC: generalized-index. #2473
Conversation
phaazon
added some commits
Jun 13, 2018
Centril
added
T-libs
T-lang
labels
Jun 13, 2018
This comment has been minimized.
This comment has been minimized.
|
Adding |
This comment has been minimized.
This comment has been minimized.
matthewjasper
commented
Jun 13, 2018
|
How does this affect |
This comment has been minimized.
This comment has been minimized.
|
I think you need to better address backwards compatibility. The fact that it's easy to rewrite old impls against the new trait isn't quite enough -- all those impls currently exist, and even new editions of the compiler need to be able to use them. Perhaps a new trait should be introduced with the more flexible definition, and a blanket impl can be provided (is this possible?) to cover the old |
This comment has been minimized.
This comment has been minimized.
Gilnaa
commented
Jun 13, 2018
|
Is it possible to avoid breakage using some kind of hack? Like changing the lang item's name to "IndexMove" and having some catchall impl that translates from the old trait to the new?
I'm pretty uncomfortable with this breakage, although I agree that the proposed trait is better than what we currently have. |
This comment has been minimized.
This comment has been minimized.
CAD97
commented
Jun 13, 2018
•
|
I believe the following is a possible solution without breakage, but purposely using bad naming:
impl <'a, Idx, T: Index<Idx>> NewIndex<'a, Idx> for T {
type Output = &'a <Self as Index<Idx>>::Output;
fn index(&'a self, idx: Idx) -> Self::Output {
Index::index(self, idx)
}
}In terms of the name, |
This comment was marked as off-topic.
This comment was marked as off-topic.
Emerentius
commented
Jun 13, 2018
•
|
It's obvious that breaking changes such as this do not fly and the author knows this. This RFC's purpose is to signal a need and to stir up discussion. The limitations of indexing have been a longstanding pain point. |
This comment has been minimized.
This comment has been minimized.
Gilnaa
commented
Jun 13, 2018
|
@emerenitus can you give an example for a place where this is needed |
This comment has been minimized.
This comment has been minimized.
|
I think I should alter the RFC to do the same thing with |
This comment has been minimized.
This comment has been minimized.
Gilnaa
commented
Jun 13, 2018
•
|
Does IndexMut make any sense in a move context? |
This comment has been minimized.
This comment has been minimized.
|
@Gilnaa it does:
|
This comment has been minimized.
This comment has been minimized.
Gilnaa
commented
Jun 13, 2018
|
Okay, but why. In what context is this useful? |
This comment has been minimized.
This comment has been minimized.
|
@durka, the blanket definition you talk about looks like a default implementation (
|
This comment has been minimized.
This comment has been minimized.
|
@Gilnaa in the context where you want to return an object that borrows, instead of a direct reference. Both immutable and mutable situations might happen. Not related to indexing, but you already do this with |
This comment was marked as off-topic.
This comment was marked as off-topic.
|
@Emerentius I have no idea what you’re talking about. Nor even how I should react. I don’t write RFCs just for the sake of it. I write RFCs because I have an idea I want to share with people and if consensus is met, the idea is merged. Every RFC that I did came from a situation that I had found problematic in Rust. Please don’t label my actions as stiring up. |
This comment was marked as off-topic.
This comment was marked as off-topic.
Gilnaa
commented
Jun 13, 2018
|
I don't think "stiring up" in this context is bad. I think he just meant "to make conversation" |
This comment has been minimized.
This comment has been minimized.
|
Anyone sees specificities with |
This comment has been minimized.
This comment has been minimized.
warlord500
commented
Jun 13, 2018
|
however in way, this change makes slices in rust proper a lot less special because of this. is it possible that this could be consider with the edition? change to a different edition will break code. |
sfackler
reviewed
Jun 13, 2018
| operator, like the `[[]]` operator or even `[move idx]` construct. This would then require adding a | ||
| new trait, like `IndexMove`, to make the whole design work. | ||
|
|
||
| ## How not to introduce a breaking change |
This comment has been minimized.
This comment has been minimized.
sfackler
Jun 13, 2018
Member
Not making a breaking change to the language is not an alternative, it's the only acceptable approach.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Slices already use the existing Index trait, they have no special behavior with respect to indexing syntax. |
This comment has been minimized.
This comment has been minimized.
|
Nominating for next lang team meeting due to urgency of the RFC wrt. editions. |
Centril
added
the
I-nominated
label
Jun 13, 2018
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
warlord500
commented
Jun 13, 2018
|
slices arent special in the sense that the act differently for the index trait. its that its current impossible to write a struct that acts nearly the exact same as a slice. in essence how do you write that a reference to |
sfackler
reviewed
Jun 13, 2018
| # Unresolved questions | ||
| [unresolved]: #unresolved-questions | ||
|
|
||
| - Should this RFC also concern `IndexMut`? |
This comment has been minimized.
This comment has been minimized.
sfackler
Jun 13, 2018
Member
Yes, this RFC also has to cover IndexMut - that trait extends Index and reuses its output type. That setup will not work with this proposed change.
This comment has been minimized.
This comment has been minimized.
|
As written, this RFC cannot be accepted, because it proposes a breaking change to std based on the definitions laid out in RFC 1105. It also cannot be enabled (as written) by the edition/epoch changes introduced in RFC 2052, because it does not allow us to change the definition of any existing item in libstd. There are two active internals threads that are discussing the possibility of enabling different kinds of index operations, including attempts to address the backward compatibility issues: Because accepting this RFC as written would be a violation of our breaking change guarantees laid out in previous RFCs, I'm going to close this for procedural reasons: we can't, according to our rules, consider this proposal as written. I would encourage anyone who wants to work on a proposal in this space to participate in one of the internals threads I linked to, and a non-breaking RFC can be posted based on that discussion.
@phaazon says that this was not their intention, so this portion of my comment is not directed at them. But I want to make it clear for all users that opening an RFC you know cannot be accepted would be a misuse of the RFC process: you should only open an RFC if you believe in good faith that your RFC can and should be accepted. Nothing @phaazon has posted suggests that this RFC was not opened in good faith, but its important to establish for everyone that this would not be how to bring attention to an issue you care about. |
withoutboats
closed this
Jun 13, 2018
This comment has been minimized.
This comment has been minimized.
|
@withoutboats couldn’t we just rewrite / move the RFC with comments from people in this thread? The proposed situation with |
This comment has been minimized.
This comment has been minimized.
|
@phaazon Yea, an RFC along those lines could be considered, because it wouldn't be a breaking change. I think it would be ideal to work out the details on one of the internals threads I linked to & start a new RFC pull request for a proposal with a non-breaking change. |
phaazon commentedJun 13, 2018
•
edited
Rendered.