-
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: New range types for Edition 2024 #3550
Conversation
I personally wouldn't call the old range types "legacy" ranges because, if the new ranges impl |
I'm huge fan of backward compatibility. Now: let range1 = 0..5;
// range1 : Range<usize>
let range2 = 0..#rit 5;
// range2 : Range<usize>
let range3 = 0..#rii 5;
// range3 : IntoRange<usize>
let range4 : Range<usize> = 0..5;
let range5 : IntoRange<usize> = 0..5; UPD: where |
This comment was marked as resolved.
This comment was marked as resolved.
This is addressed in the RFC under Use legacy range types as the iterators for the new range types. |
I like this. I see one problem, however. Any crate which provides a container that can be sliced which is not updated will require This could be solved with Maybe it's also worth a mention that--without some sort of blanket impl--all of stdlib is going to need to implement Index/IndexMut for both. |
I think it would have to be an implicit conversion since |
What is |
just some user-defined type with a type parameter pub struct Wrapper<T>(T);
impl<T: Index<I>, I> Index<I> for Wrapper<T> {
type Output = T::Output;
fn index(&self, idx: I) -> &Self::Output {
self.0.index(idx)
}
} |
@programmerjake Could the compiler use the fact that it is the compiler to use specialization here? I dunno what the state of that is these days but it might be better than an implicit conversion. I hate blanket impls in stdlib, but it's a close race with how much I hate implicit conversions. |
@ahicks92 thanks for bringing this up, I hadn't considered the indexing case. I think many common cases will be covered by I will update the migration and drawbacks sections to cover this. I would not support adding a blanket impl, specialization, or implicit conversion even if they were possible. I think we should take a different approach:
|
Well, I do a lot of mathematical code as it is, and even as Rust is today Rust is very verbose a lot of the time for such cases. That's not really a complaint about Rust as such, But I don't want to deal with:
Where The worst practical case of slicing with this proposal would be crates.io is pretty big and pretty full of unmaintained stuff. I think "let crates start migrating ASAP" is a good point but it doesn't answer what to do about anything older that's not maintained or anything that doesn't notice this is coming in time. I don't know how much of a problem that would be, and I'm not sure how one would quantify it either. But that might be a good thing to try to do if it can be done. |
I will just mention that |
In std, the only affected impls would be:
The So I'd say the only serious one there is |
I am thinking about it like this:
I understand that the other motivation is about having ranges inside other types, but leaving that aside the unstated premise here seems to me to be that we are claiming that working around lack of Copy today is more ubiquitous than needing to convert to legacy types in Rust 2024. I could believe that is true, my use cases aren't even close to all possible use cases, but not without proof. I don't consider stdlib to be interesting. From a language perspective solutions up to and including hacking the compiler for stdlib backward compatibility are feasible. Solving it is important and interesting but the solution space is large enough there that there is certainly a solution and the question isn't "if", it's "which". |
My thoughts:
|
I don't think we can. One either picks 2024 and converts for 2021 crates, or picks 2021 and converts for 2024 crates. Right? So if this is an issue you lose out either way. Also stay on the old edition doesn't work because eventually the new edition gets something you need. But as you've already stated data is a good idea. I'm willing to argue contingent on this being widespread all day long but the entire thing depends on if it's widespread or not. If we don't have one someone should really figure out how to run a query over all of crates.io, probably via docs.rs, to be like |
Not really. For the indexing issue, they already support legacy range types and they can just add impls for the new types. Functions that take a specific range type can use The only case where conversion is unavoidable is if you're using the new range types on code expecting old range types. All new code can and should be written to accept both. Essentially, the issue is forwards compatibility, not backwards compatibility. |
I doubt anyone is going to cover both. That's not a big ask but you then have to teach newbies to the language that due to legacy reasons they'd better. As far as I know, every other edition has not required supporting the older edition in order to depend on crates supporting the newer one. Perhaps it has and I've missed it. But if not, this is establishing the precedent. |
The |
for |
I think a way forward could be to add the new range types as unstable to the standard library, so we can start on the detailed design of those types and their API. I don't think those types should be stabilized before we know what will happen with the related lang changes, but adding an unstable (And perhaps there are good arguments for adding these types regardless of what happens with For this RFC, I'd be happy to resolve my rfcbot concern if an unresolved question is added on whether the proposed migration is not too disruptive, and how to properly document and execute the ecosystem migration, to make sure that is taken into consideration before stabilization. |
We briefly discussed this in the libs-api meeting. We're happy to see a PR for adding |
If ranges are overhauled, should For instance Related: rust-lang/rust#42168 |
Let's do this then =) |
A minor thing the RFC doesn't cover is a migration path for APIs that return legacy ranges. For example, Anyway, I agree we should move forward with a caveat about backing this out if the disruption is too great. |
Status update: I was hoping to get back to this over the weekend but unfortunately didn't have time. I will try to get to it this week. |
@rfcbot resolve No clean migration path. |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. This will be merged soon. |
The FCP for RFC 3550 completed. Let's prepare it to be merged.
The teams have accepted this RFC and it has now been merged. Thanks to @pitaj for pushing this work forward, and thanks to all those who reviewed and contributed helpful feedback. For further updates, follow the tracking issue: |
Change the range operators
a..b
,a..
, anda..=b
to resolve to new typesops::range::Range
,ops::range::RangeFrom
, andops::range::RangeInclusive
in Edition 2024. These new types will not implementIterator
, instead implementingCopy
andIntoIterator
.Closes #2848
Pre-RFC discussion on IRLO
🖥️ Rendered
Analysis of impact on crates in the wild
Tracking: