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: movable array iterators #2185
Conversation
This comment has been minimized.
This comment has been minimized.
|
I very much want this, but what is return type of Or maybe
I believe that in a method taking |
This comment has been minimized.
This comment has been minimized.
|
Please prefer line comments so I can respond without copying :)
I think there's a need to be able to drop each elements individually (in other words, only in the range that is not moved out). So we need ManuallyDrop on each element, and trasmuting should be the easiest so far. |
This comment has been minimized.
This comment has been minimized.
|
You can call |
This comment has been minimized.
This comment has been minimized.
|
Good. I will update the text later. |
bluss
reviewed
Oct 24, 2017
| ```rust | ||
| [1, 2].into_iter(); | ||
| // This was originally yielding references, but now values. | ||
| ``` |
This comment has been minimized.
This comment has been minimized.
bluss
Oct 24, 2017
•
This is pretty much ensured to break actual code for many users, both in crater (that we can test, find and maybe fix), and lots of code we can't find or test. Maybe we can begin warning for this long before the new iterator is implemented?
This comment has been minimized.
This comment has been minimized.
ishitatsuyuki
Oct 25, 2017
Author
Member
Personally speaking, I don't think people would use into_iter despite the fact it yields references, and they would just iter instead. Thus I think fixing after a crater should be sufficient.
This comment has been minimized.
This comment has been minimized.
bluss
Oct 25, 2017
We don't reach all rust code in the world with crater. If the break is wide spread, we have to be more careful.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
main--
Oct 25, 2017
Oh I see. [1].into_iter() currently resolves to the impl for &[_; _] which the new [_; _] impl would override, right?
This comment has been minimized.
This comment has been minimized.
scottmcm
added
the
T-libs
label
Oct 25, 2017
This comment has been minimized.
This comment has been minimized.
cristicbz
commented
Oct 31, 2017
This could be done without stabilising impl<T> Iterator for IntoIter<[T; 1]> { ... }
impl<T> Iterator for IntoIter<[T; 2]> { ... }
impl<T> Iterator for IntoIter<[T; 3]> { ... }
// ...
impl<T> Iterator for IntoIter<[T; 32]> { ... }with all the impls calling to some shared unsafe method to avoid duplication. Has a nice migration story for when const generics land, just replacing with impl<T, const N> Iterator for IntoIter<[T; N]> {} |
This comment has been minimized.
This comment has been minimized.
|
Please take a look, I think I have addressed the concerns. |
This comment has been minimized.
This comment has been minimized.
|
This looks great to me, thanks for writing it up! |
This comment has been minimized.
This comment has been minimized.
|
struct IntoIter<T> { ... }
impl<T> Drop for IntoIter<[T; 0]> { ... }
impl<T> Drop for IntoIter<[T; 1]> { ... } // error: Implementations of Drop cannot be specialized
...
// I expect this will work
struct IntoIter<T, const N: usize> { ... }
impl<T, const N: usize> Drop for IntoIter<T, N>
// This works today
struct IntoIter<T, A> where A: FixedSizeArray<T> { ... }
impl<T, A> Drop for IntoIter<T, A> where A: FixedSizeArray<T> { ... }EDIT: typo |
This comment has been minimized.
This comment has been minimized.
|
@sinkuu What do you mean by |
This comment has been minimized.
This comment has been minimized.
|
Presumably Unsize. |
This comment has been minimized.
This comment has been minimized.
|
Should we make multiple IntoIter structs until const generic lands? Like this: I think this should resolve the specialization problem, alongside reducing the template complexity, so we can store pointers (or unsafe slices) inside the struct. |
This comment has been minimized.
This comment has been minimized.
I want this feature, but I don’t think I want to stabilize such an API. It’d be harder to generalize once const generics land, too.
I don’t understand what you mean here. The point of |
This comment has been minimized.
This comment has been minimized.
I'm afraid that even
We need to save the range we have consumed with the iterator. It can be either usize-indexed or just start-end pointer. |
This comment has been minimized.
This comment has been minimized.
|
Changing the signature of stable APIs is not acceptable, so I’m afraid that this implies we should not stabilize anything here without const generics. Self-referential pointers would become invalid when the iterator is moved. It has to be indices. (Two of them, or a |
This comment has been minimized.
This comment has been minimized.
|
I've come up with a partial stabilization plan, please let me know if this is possible. As the signature of the iterator struct is subject to change, we will be keeping that struct(s) unstable until const generics land. I will call this struct
impl<T> IntoIterator for [T; 32] {
type Item = T;
type IntoIter = UnstableIntoIter32<T>;
fn into_iter(self) -> T { ... }
}I have no idea if this implementation will be accepted as stable in the compiler, so we can use it without the ability to annotate the type. |
This comment has been minimized.
This comment has been minimized.
|
Instead of a specific |
This comment has been minimized.
This comment has been minimized.
|
Would it be compatible to replace struct IntoIter0<T>{ .. };
..
struct IntoIter32<T>{ .. };with type IntoIter0<T> = IntoIter<T, const 0>;
..
type IntoIter32<T> = IntoIter<T, const 32>;once const generics land? Then the eventual type would be the nice one, and the residual cruft is just a bunch of deprecated type aliases, which should be easy to maintain and ignore in the docs. |
This comment has been minimized.
This comment has been minimized.
bluss
commented
Nov 20, 2017
•
|
We can do one thing before we even start the implementation: Work on deprecating & future warning the existing |
This comment has been minimized.
This comment has been minimized.
|
I experimented with an implementation of deprecation warning, but it seems that I can't avoid one particular false positive: https://play.rust-lang.org/?gist=8b69b43bc947bf112c0f20d0e58b3add&version=stable Basically, the differences between the below cannot be detected without changing the signature:
|
aturon
assigned
sfackler
Jan 23, 2018
This comment has been minimized.
This comment has been minimized.
|
We discussed this at the @rust-lang/libs meeting today, and feel like this won't really be actionable until integer generics are implemented. @rfcbot fcp postpone |
rfcbot
added
the
proposed-final-comment-period
label
Jan 24, 2018
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Jan 24, 2018
•
|
Team member @sfackler has proposed to postpone this. The next step is review by the rest of the tagged teams: No concerns currently listed. Once these reviewers reach consensus, this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
This comment has been minimized.
This comment has been minimized.
bluss
commented
Jan 24, 2018
|
@sfackler What do you think about starting to warn / soft deprecate |
This comment has been minimized.
This comment has been minimized.
|
I have mentioned that if we don't stabilize the iterator types, we can implement it with macro generated iterators and partially stabilize the into_iter() function only. |
This comment has been minimized.
This comment has been minimized.
|
Not sure - we haven't really done anything like that before. @aturon thoughts? I am personally not a fan of the current "up to size 32" approach, and don't really want to expand that further. |
This comment has been minimized.
This comment has been minimized.
|
@sfackler - what we only can do currently is that "up to size 32" approach; it should not be a blocker to improve array usability. I originally thought that the main concern is backwards compatibility, which needs a lint to be developed. As I emphasized above, const generics is not a blocker for this, just a wishlist item. As const generics is an approved RFC, we can expect the stabilization at the same time. |
This comment has been minimized.
This comment has been minimized.
|
@bluss I'd be in favor. |
rfcbot
added
final-comment-period
and removed
proposed-final-comment-period
labels
Feb 14, 2018
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Feb 14, 2018
|
|
3 similar comments
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Feb 14, 2018
|
|
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Feb 14, 2018
|
|
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Feb 14, 2018
|
|
rfcbot
added
the
final-comment-period
label
Feb 14, 2018
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Feb 24, 2018
|
The final comment period is now complete. |
Centril
added
the
postponed
label
Feb 24, 2018
This comment has been minimized.
This comment has been minimized.
|
Closing since FCP with the proposal to postpone is now complete. |
ishitatsuyuki commentedOct 21, 2017
•
edited
Rendered