-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Implement Index and IndexMut for Vec #15652
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
Conversation
This should probably be blocked on #15525, or else we'll risk some surprising segfaults and invalid code. |
It'd be nice to talk about the plan for what happens with |
Yes, |
There are many methods on slice that aren't currently available on The verdict about the ergonomics of slice/ |
So perhaps deprecate |
Assuming But in the meantime I'm in favor of deprecating |
So I tried deprecating |
Can they be changed in this PR? (Doing it in a separate commit would be nice, if it does work.) |
Not very easily - it would mean using cfgs for 10s or 100s of methods, even then I'm not sure if you can gate #deprecated on a cfg, so you would still get warnings. Much easier to wait for a snapshot. |
#15525 has a fix and doing anything for |
Filed #15672 as a follow up to deprecate |
This shouldn't need to wait for a snapshot, everything should be able to move immediately to the new syntax, what were the roadblocks you encountered? |
I changed the first error I saw in librustrt and that gave me a compile error when doing the stage0 build because indexing for Vecs is not supported. Perhaps the new indexing work in the compiler hasn't made it to the snapshot and that is what we need? error: cannot index a value of type |
Maybe that isn't derefing, and so needs |
Yeah, on second glance it looks like it might be a problem like that - I tried changing another use of |
And it turns out sometimes you want a |
I think that's handled by |
That won't deref |
No, it shouldn't. (Otherwise vector indexing would be useless for non- |
|
So, that might all be moot - #12825 is a problem here too - the compiler prefers IndexMut to Index which causes problems if the vec is not mutable. So, I think I will just implement Index and leave |
I believe that no matter what we will want these implementations in any future world basically exactly as-is, so I'm going to r+ this. We can work on the deprecation of |
@alexcrichton I believe it might be better for now, not to implement IndexMut - it prevents Index working. In that case deprecating |
@alexcrichton r? on just Vec::get ? |
There are some doc test failures: https://travis-ci.org/rust-lang/rust/jobs/29948445 |
<3 this makes writing code involving Vec a jillion times less frustrating |
minor: Various small fixes
No description provided.