Skip to content

Commit e557d29

Browse files
committed
Auto merge of rust-lang#118769 - pitaj:range-experiment, r=<try>
Range experiment Meant for a crater run to see how much breakage we can expect outside of the Iterator methods themselves https://internals.rust-lang.org/t/pre-rfc-fixing-range-by-2027/19936
2 parents 6f40082 + f74b74c commit e557d29

File tree

128 files changed

+4320
-1921
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

128 files changed

+4320
-1921
lines changed

Cargo.lock

+22-13
Original file line numberDiff line numberDiff line change
@@ -3006,9 +3006,9 @@ checksum = "dc375e1527247fe1a97d8b7156678dfe7c1af2fc075c9a4db3690ecd2a148068"
30063006

30073007
[[package]]
30083008
name = "proc-macro2"
3009-
version = "1.0.63"
3009+
version = "1.0.70"
30103010
source = "registry+https://github.com/rust-lang/crates.io-index"
3011-
checksum = "7b368fba921b0dce7e60f5e04ec15e565b3303972b42bcfde1d0713b881959eb"
3011+
checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b"
30123012
dependencies = [
30133013
"unicode-ident",
30143014
]
@@ -3064,9 +3064,8 @@ checksum = "07589615d719a60c8dd8a4622e7946465dfef20d1a428f969e3443e7386d5f45"
30643064

30653065
[[package]]
30663066
name = "quote"
3067-
version = "1.0.29"
3068-
source = "registry+https://github.com/rust-lang/crates.io-index"
3069-
checksum = "573015e8ab27661678357f27dc26460738fd2b6c86e46f386fde94cb5d913105"
3067+
version = "1.0.33"
3068+
source = "git+https://github.com/pitaj/quote#44feebf0594b255a511ff20890a7acbf4d6aeed1"
30703069
dependencies = [
30713070
"proc-macro2",
30723071
]
@@ -3349,11 +3348,10 @@ dependencies = [
33493348
[[package]]
33503349
name = "rustc-rayon"
33513350
version = "0.5.0"
3352-
source = "registry+https://github.com/rust-lang/crates.io-index"
3353-
checksum = "eb81aadc8837ca6ecebe0fe1353f15df83b3b3cc2cf7a8afd571bc22aa121710"
3351+
source = "git+https://github.com/pitaj/rustc-rayon#e76e554512ce25abb48f4118576ede5d7a457918"
33543352
dependencies = [
33553353
"either",
3356-
"rustc-rayon-core",
3354+
"rustc-rayon-core 0.5.0 (git+https://github.com/pitaj/rustc-rayon)",
33573355
]
33583356

33593357
[[package]]
@@ -3368,6 +3366,17 @@ dependencies = [
33683366
"num_cpus",
33693367
]
33703368

3369+
[[package]]
3370+
name = "rustc-rayon-core"
3371+
version = "0.5.0"
3372+
source = "git+https://github.com/pitaj/rustc-rayon#e76e554512ce25abb48f4118576ede5d7a457918"
3373+
dependencies = [
3374+
"crossbeam-channel",
3375+
"crossbeam-deque",
3376+
"crossbeam-utils",
3377+
"num_cpus",
3378+
]
3379+
33713380
[[package]]
33723381
name = "rustc-semver"
33733382
version = "1.1.0"
@@ -3697,7 +3706,7 @@ dependencies = [
36973706
"portable-atomic",
36983707
"rustc-hash",
36993708
"rustc-rayon",
3700-
"rustc-rayon-core",
3709+
"rustc-rayon-core 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
37013710
"rustc_arena",
37023711
"rustc_graphviz",
37033712
"rustc_index",
@@ -4023,7 +4032,7 @@ version = "0.0.0"
40234032
dependencies = [
40244033
"libloading 0.7.4",
40254034
"rustc-rayon",
4026-
"rustc-rayon-core",
4035+
"rustc-rayon-core 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
40274036
"rustc_ast",
40284037
"rustc_ast_lowering",
40294038
"rustc_ast_passes",
@@ -4188,7 +4197,7 @@ dependencies = [
41884197
"measureme",
41894198
"polonius-engine",
41904199
"rustc-rayon",
4191-
"rustc-rayon-core",
4200+
"rustc-rayon-core 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
41924201
"rustc_apfloat",
41934202
"rustc_arena",
41944203
"rustc_ast",
@@ -4388,7 +4397,7 @@ version = "0.0.0"
43884397
dependencies = [
43894398
"field-offset",
43904399
"measureme",
4391-
"rustc-rayon-core",
4400+
"rustc-rayon-core 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
43924401
"rustc_data_structures",
43934402
"rustc_errors",
43944403
"rustc_hir",
@@ -4407,7 +4416,7 @@ name = "rustc_query_system"
44074416
version = "0.0.0"
44084417
dependencies = [
44094418
"parking_lot 0.12.1",
4410-
"rustc-rayon-core",
4419+
"rustc-rayon-core 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
44114420
"rustc_ast",
44124421
"rustc_data_structures",
44134422
"rustc_errors",

Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -111,5 +111,8 @@ rustc-std-workspace-core = { path = 'library/rustc-std-workspace-core' }
111111
rustc-std-workspace-alloc = { path = 'library/rustc-std-workspace-alloc' }
112112
rustc-std-workspace-std = { path = 'library/rustc-std-workspace-std' }
113113

114+
rustc-rayon = { git = "https://github.com/pitaj/rustc-rayon" }
115+
quote = { git = "https://github.com/pitaj/quote" }
116+
114117
[patch."https://github.com/rust-lang/rust-clippy"]
115118
clippy_lints = { path = "src/tools/clippy/clippy_lints" }

compiler/rustc_borrowck/src/borrow_set.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ impl<'tcx> BorrowSet<'tcx> {
161161
}
162162

163163
pub(crate) fn indices(&self) -> impl Iterator<Item = BorrowIndex> {
164-
BorrowIndex::from_usize(0)..BorrowIndex::from_usize(self.len())
164+
(BorrowIndex::from_usize(0)..BorrowIndex::from_usize(self.len())).into_iter()
165165
}
166166

167167
pub(crate) fn iter_enumerated(&self) -> impl Iterator<Item = (BorrowIndex, &BorrowData<'tcx>)> {

compiler/rustc_borrowck/src/region_infer/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2140,7 +2140,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
21402140
// we still want to screen for an "interesting" point to
21412141
// highlight (e.g., a call site or something).
21422142
let target_scc = self.constraint_sccs.scc(target_region);
2143-
let mut range = 0..path.len();
2143+
let mut range = (0..path.len()).into_iter();
21442144

21452145
// As noted above, when reporting an error, there is typically a chain of constraints
21462146
// leading from some "source" region which must outlive some "target" region.

compiler/rustc_builtin_macros/src/deriving/cmp/partial_ord.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub fn expand_deriving_partial_ord(
2828
// No data, placing the tag check first makes codegen simpler
2929
0 => true,
3030
1..=2 => false,
31-
_ => (0..dataful.len() - 1).any(|i| {
31+
_ => (0..dataful.len() - 1).into_iter().any(|i| {
3232
if dataful[i]
3333
&& let Some(idx) = dataful[i + 1..].iter().position(|v| *v)
3434
{

compiler/rustc_const_eval/src/interpret/projection.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ pub trait Projectable<'tcx, Prov: Provenance>: Sized + std::fmt::Debug {
9999
/// A type representing iteration over the elements of an array.
100100
pub struct ArrayIterator<'tcx, 'a, Prov: Provenance, P: Projectable<'tcx, Prov>> {
101101
base: &'a P,
102-
range: Range<u64>,
102+
range: <Range<u64> as IntoIterator>::IntoIter,
103103
stride: Size,
104104
field_layout: TyAndLayout<'tcx>,
105105
_phantom: PhantomData<Prov>, // otherwise it says `Prov` is never used...
@@ -280,7 +280,13 @@ where
280280
debug!("project_array_fields: {base:?} {len}");
281281
base.offset(len * stride, self.layout_of(self.tcx.types.unit).unwrap(), self)?;
282282
// Create the iterator.
283-
Ok(ArrayIterator { base, range: 0..len, stride, field_layout, _phantom: PhantomData })
283+
Ok(ArrayIterator {
284+
base,
285+
range: (0..len).into_iter(),
286+
stride,
287+
field_layout,
288+
_phantom: PhantomData,
289+
})
284290
}
285291

286292
/// Subslicing

compiler/rustc_error_codes/src/error_codes/E0562.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Erroneous code example:
55

66
```compile_fail,E0562
77
fn main() {
8-
let count_to_ten: impl Iterator<Item=usize> = 0..10;
8+
let count_to_ten: impl IntoIterator<Item=usize> = 0..10;
99
// error: `impl Trait` not allowed outside of function and inherent method
1010
// return types
1111
for i in count_to_ten {
@@ -17,7 +17,7 @@ fn main() {
1717
Make sure `impl Trait` only appears in return-type position.
1818

1919
```
20-
fn count_to_n(n: usize) -> impl Iterator<Item=usize> {
20+
fn count_to_n(n: usize) -> impl IntoIterator<Item=usize> {
2121
0..n
2222
}
2323

compiler/rustc_metadata/src/rmeta/decoder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ impl<T: ParameterizedOverTcx> LazyValue<T> {
251251
}
252252

253253
struct DecodeIterator<'a, 'tcx, T> {
254-
elem_counter: std::ops::Range<usize>,
254+
elem_counter: <std::ops::Range<usize> as IntoIterator>::IntoIter,
255255
dcx: DecodeContext<'a, 'tcx>,
256256
_phantom: PhantomData<fn() -> T>,
257257
}
@@ -294,7 +294,7 @@ impl<T: ParameterizedOverTcx> LazyArray<T> {
294294
{
295295
let mut dcx = metadata.decoder(self.position.get());
296296
dcx.lazy_state = LazyState::NodeStart(self.position);
297-
DecodeIterator { elem_counter: (0..self.num_elems), dcx, _phantom: PhantomData }
297+
DecodeIterator { elem_counter: (0..self.num_elems).into_iter(), dcx, _phantom: PhantomData }
298298
}
299299
}
300300

compiler/rustc_middle/src/mir/interpret/allocation/init_mask.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ impl InitMaskMaterialized {
534534
end: Size,
535535
is_init: bool,
536536
) -> Option<Size> {
537-
(start..end).find(|&i| init_mask.get(i) == is_init)
537+
(start..end).into_iter().find(|&i| init_mask.get(i) == is_init)
538538
}
539539

540540
let result = find_bit_fast(self, start, end, is_init);

compiler/rustc_parse/src/parser/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2905,7 +2905,7 @@ impl<'a> Parser<'a> {
29052905
}
29062906

29072907
pub fn is_diff_marker(&mut self, long_kind: &TokenKind, short_kind: &TokenKind) -> bool {
2908-
(0..3).all(|i| self.look_ahead(i, |tok| tok == long_kind))
2908+
(0..3).into_iter().all(|i| self.look_ahead(i, |tok| tok == long_kind))
29092909
&& self.look_ahead(3, |tok| tok == short_kind)
29102910
}
29112911

compiler/rustc_parse/src/parser/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1082,7 +1082,7 @@ impl<'a> Parser<'a> {
10821082
// we are in has non-skipped delimiters. Look for skipped
10831083
// delimiters in the lookahead range.
10841084
let tree_cursor = &self.token_cursor.tree_cursor;
1085-
let all_normal = (0..dist).all(|i| {
1085+
let all_normal = (0..dist).into_iter().all(|i| {
10861086
let token = tree_cursor.look_ahead(i);
10871087
!matches!(token, Some(TokenTree::Delimited(.., Delimiter::Invisible, _)))
10881088
});

library/alloc/src/collections/btree/node.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ impl<'a, K: 'a, V: 'a, Type> NodeRef<marker::Mut<'a>, K, V, Type> {
546546
impl<'a, K, V> NodeRef<marker::Mut<'a>, K, V, marker::Internal> {
547547
/// # Safety
548548
/// Every item returned by `range` is a valid edge index for the node.
549-
unsafe fn correct_childrens_parent_links<R: Iterator<Item = usize>>(&mut self, range: R) {
549+
unsafe fn correct_childrens_parent_links<R: IntoIterator<Item = usize>>(&mut self, range: R) {
550550
for i in range {
551551
debug_assert!(i <= self.len());
552552
unsafe { Handle::new_edge(self.reborrow_mut(), i) }.correct_parent_link();

library/alloc/src/collections/vec_deque/tests.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -899,10 +899,13 @@ fn test_extend_impl(trusted_len: bool) {
899899
Self { test: VecDeque::new(), expected: VecDeque::new(), trusted_len }
900900
}
901901

902-
fn test_extend<I>(&mut self, iter: I)
902+
fn test_extend<I, IntoIter>(&mut self, iter: I)
903903
where
904-
I: Iterator<Item = usize> + TrustedLen + Clone,
904+
I: IntoIterator<IntoIter = IntoIter>,
905+
IntoIter: Iterator<Item = usize> + TrustedLen + Clone,
905906
{
907+
let iter = iter.into_iter();
908+
906909
struct BasicIterator<I>(I);
907910
impl<I> Iterator for BasicIterator<I>
908911
where

library/alloc/src/vec/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1943,7 +1943,7 @@ impl<T, A: Allocator> Vec<T, A> {
19431943
/// #![feature(vec_push_within_capacity)]
19441944
///
19451945
/// use std::collections::TryReserveError;
1946-
/// fn from_iter_fallible<T>(iter: impl Iterator<Item=T>) -> Result<Vec<T>, TryReserveError> {
1946+
/// fn from_iter_fallible<T>(iter: impl IntoIterator<Item=T>) -> Result<Vec<T>, TryReserveError> {
19471947
/// let mut vec = Vec::new();
19481948
/// for value in iter {
19491949
/// if let Err(value) = vec.push_within_capacity(value) {

library/alloc/tests/str.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -590,15 +590,15 @@ mod slice_index {
590590

591591
good: data[0..=5] == "abcdef";
592592
good: data[{
593-
let mut iter = 0..=5;
593+
let mut iter = core::ops::range::legacy::RangeInclusive::from(0..=5);
594594
iter.by_ref().count(); // exhaust it
595595
iter
596596
}] == "";
597597

598598
// 0..=6 is out of bounds before exhaustion, so it
599599
// stands to reason that it still would be after.
600600
bad: data[{
601-
let mut iter = 0..=6;
601+
let mut iter = core::ops::range::legacy::RangeInclusive::from(0..=6);
602602
iter.by_ref().count(); // exhaust it
603603
iter
604604
}];

library/core/benches/iter.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -493,42 +493,42 @@ fn bench_next_chunk_trusted_random_access(b: &mut Bencher) {
493493

494494
#[bench]
495495
fn bench_next_chunk_filter_even(b: &mut Bencher) {
496-
let a = (0..1024).next_chunk::<1024>().unwrap();
496+
let a = (0..1024).into_iter().next_chunk::<1024>().unwrap();
497497

498498
b.iter(|| black_box(&a).iter().filter(|&&i| i % 2 == 0).next_chunk::<32>())
499499
}
500500

501501
#[bench]
502502
fn bench_next_chunk_filter_predictably_true(b: &mut Bencher) {
503-
let a = (0..1024).next_chunk::<1024>().unwrap();
503+
let a = (0..1024).into_iter().next_chunk::<1024>().unwrap();
504504

505505
b.iter(|| black_box(&a).iter().filter(|&&i| i < 100).next_chunk::<32>())
506506
}
507507

508508
#[bench]
509509
fn bench_next_chunk_filter_mostly_false(b: &mut Bencher) {
510-
let a = (0..1024).next_chunk::<1024>().unwrap();
510+
let a = (0..1024).into_iter().next_chunk::<1024>().unwrap();
511511

512512
b.iter(|| black_box(&a).iter().filter(|&&i| i > 900).next_chunk::<32>())
513513
}
514514

515515
#[bench]
516516
fn bench_next_chunk_filter_map_even(b: &mut Bencher) {
517-
let a = (0..1024).next_chunk::<1024>().unwrap();
517+
let a = (0..1024).into_iter().next_chunk::<1024>().unwrap();
518518

519519
b.iter(|| black_box(&a).iter().filter_map(|&i| (i % 2 == 0).then(|| i)).next_chunk::<32>())
520520
}
521521

522522
#[bench]
523523
fn bench_next_chunk_filter_map_predictably_true(b: &mut Bencher) {
524-
let a = (0..1024).next_chunk::<1024>().unwrap();
524+
let a = (0..1024).into_iter().next_chunk::<1024>().unwrap();
525525

526526
b.iter(|| black_box(&a).iter().filter_map(|&i| (i < 100).then(|| i)).next_chunk::<32>())
527527
}
528528

529529
#[bench]
530530
fn bench_next_chunk_filter_map_mostly_false(b: &mut Bencher) {
531-
let a = (0..1024).next_chunk::<1024>().unwrap();
531+
let a = (0..1024).into_iter().next_chunk::<1024>().unwrap();
532532

533533
b.iter(|| black_box(&a).iter().filter_map(|&i| (i > 900).then(|| i)).next_chunk::<32>())
534534
}

library/core/src/array/iter.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,9 @@ impl<T, const N: usize> IntoIter<T, N> {
132132
/// unsafe { Ok(buffer.transpose().assume_init()) }
133133
/// }
134134
///
135-
/// let r: [_; 4] = next_chunk(&mut (10..16)).unwrap();
135+
/// let r: [_; 4] = next_chunk(&mut (10..16).into_iter()).unwrap();
136136
/// assert_eq!(r, [10, 11, 12, 13]);
137-
/// let r: IntoIter<_, 40> = next_chunk(&mut (10..16)).unwrap_err();
137+
/// let r: IntoIter<_, 40> = next_chunk(&mut (10..16).into_iter()).unwrap_err();
138138
/// assert_eq!(r.collect::<Vec<_>>(), vec![10, 11, 12, 13, 14, 15]);
139139
/// ```
140140
#[unstable(feature = "array_into_iter_constructors", issue = "91583")]

library/core/src/escape.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Helper code for character escaping.
22
33
use crate::ascii;
4+
use crate::iter::range::RangeIter;
45
use crate::num::NonZeroUsize;
56
use crate::ops::Range;
67

@@ -68,14 +69,14 @@ pub(crate) struct EscapeIterInner<const N: usize> {
6869
pub(crate) data: [ascii::Char; N],
6970

7071
// Invariant: alive.start <= alive.end <= N.
71-
pub(crate) alive: Range<u8>,
72+
pub(crate) alive: RangeIter<u8>,
7273
}
7374

7475
impl<const N: usize> EscapeIterInner<N> {
7576
pub fn new(data: [ascii::Char; N], alive: Range<u8>) -> Self {
7677
const { assert!(N < 256) };
7778
debug_assert!(alive.start <= alive.end && usize::from(alive.end) <= N, "{alive:?}");
78-
Self { data, alive }
79+
Self { data, alive: alive.into_iter() }
7980
}
8081

8182
pub fn from_array<const M: usize>(array: [ascii::Char; M]) -> Self {
@@ -87,15 +88,15 @@ impl<const N: usize> EscapeIterInner<N> {
8788
}
8889

8990
pub fn as_ascii(&self) -> &[ascii::Char] {
90-
&self.data[usize::from(self.alive.start)..usize::from(self.alive.end)]
91+
&self.data[usize::from(self.alive.inner.start)..usize::from(self.alive.inner.end)]
9192
}
9293

9394
pub fn as_str(&self) -> &str {
9495
self.as_ascii().as_str()
9596
}
9697

9798
pub fn len(&self) -> usize {
98-
usize::from(self.alive.end - self.alive.start)
99+
usize::from(self.alive.inner.end - self.alive.inner.start)
99100
}
100101

101102
pub fn next(&mut self) -> Option<u8> {

0 commit comments

Comments
 (0)