rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
97.39k stars 12.59k forks source link

Tracking Issue for RFC 3550: New range types #123741

Open traviscross opened 5 months ago

traviscross commented 5 months ago

This is a tracking issue for the RFC 3550: New range types

The feature gate for the issue is #![feature(new_range)].

Tracking issue for the library change:

About tracking issues

Tracking issues are used to record the overall progress of implementation. They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions. A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature. Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.

Steps

Unresolved Questions

Related

cc @pitaj

orlp commented 4 months ago

To see which iterator methods we may want to add to the new ranges, I did an informal search on Github using the following query:

language:rust NOT is:fork /\W\s*\(\s*\w*\s*\.\.=?\s*\w*\s*\)\s*.\s*method\s*\(/

I matched on anything that looks like ( <> .. <> ) or ( <> ..= <> ) that is not immediately preceded by some identifier character, to avoid matching things like vec.drain(..).map(_).

Example for map: search.

This isn't perfect but captures a rough amount of usage. Just looking by the number of matches:

I personally think filter is a decent cut-off, which gives the inherent methods map, rev, collect, for_each, step_by, filter.

pitaj commented 4 months ago

Any reason you left out step_by from your final list?

orlp commented 4 months ago

@pitaj Nope, just a clerical error. I fixed it.

programmerjake commented 4 months ago

another common method that was omitted: len() (idk how many instances since github gave an error when I tried the search)

orlp commented 4 months ago

@programmerjake There is no len() on Iterator.

programmerjake commented 4 months ago

@programmerjake There is no len() on Iterator.

there is on ExactSizeIterator: https://doc.rust-lang.org/std/ops/struct.Range.html#impl-ExactSizeIterator-for-Range%3Ci8%3E

orlp commented 4 months ago

Right. I think honestly len probably makes sense regardless of whether an iterator implements it and/or how many people currently are calling it.

pitaj commented 4 months ago

I'd rather we have a better solution for len than ExactSizeIterator since, as proposed, even the new iterators for Range<u32> and RangeInclusive<i16> don't implement it.

orlp commented 4 months ago

Ugh I forgot, there's still the problem that fn len(&self) -> usize doesn't work on ranges larger than usize, nor the 0..=usize::MAX range for usize itself.

traviscross commented 4 months ago

Let's continue that discussion about which methods to add in a separate issue here rather than on the tracking issue.

traviscross commented 2 months ago

@rustbot labels -A-edition-2024 +A-maybe-future-edition -S-tracking-at-risk

This is, unfortunately, not likely to have all the pieces in place in time to ship with the Rust 2024 edition, so we're going to drop the label.

Thanks to all those who have been working on this, and we hope to see this ship in a future edition.

GrigorenkoPV commented 2 months ago

This is, unfortunately, not likely to have all the pieces in place in time to ship with the Rust 2024 edition, so we're going to drop the label.

What things are missing so far?

traviscross commented 2 months ago

What things are missing so far?

See the issue description above. We need to check off all of those boxes in order to land this in any edition.