Skip to content

Commit 95eaadc

Browse files
committed
std::range
1 parent 6c1d960 commit 95eaadc

17 files changed

+42
-40
lines changed

Diff for: library/std/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,8 @@ pub use core::option;
530530
pub use core::pin;
531531
#[stable(feature = "rust1", since = "1.0.0")]
532532
pub use core::ptr;
533+
#[unstable(feature = "new_range_api", issue = "125687")]
534+
pub use core::range;
533535
#[stable(feature = "rust1", since = "1.0.0")]
534536
pub use core::result;
535537
#[stable(feature = "rust1", since = "1.0.0")]

Diff for: tests/mir-opt/pre-codegen/range_iter.inclusive_loop.PreCodegen.after.panic-abort.mir

+5-5
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ fn inclusive_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () {
1919
scope 2 {
2020
debug x => _9;
2121
}
22-
scope 5 (inlined iter::range::<impl Iterator for RangeInclusive<u32>>::next) {
22+
scope 5 (inlined iter::range::<impl Iterator for std::ops::RangeInclusive<u32>>::next) {
2323
}
2424
}
25-
scope 3 (inlined RangeInclusive::<u32>::new) {
25+
scope 3 (inlined std::ops::RangeInclusive::<u32>::new) {
2626
}
27-
scope 4 (inlined <RangeInclusive<u32> as IntoIterator>::into_iter) {
27+
scope 4 (inlined <std::ops::RangeInclusive<u32> as IntoIterator>::into_iter) {
2828
}
2929

3030
bb0: {
31-
_4 = RangeInclusive::<u32> { start: copy _1, end: copy _2, exhausted: const false };
31+
_4 = std::ops::RangeInclusive::<u32> { start: copy _1, end: copy _2, exhausted: const false };
3232
StorageLive(_5);
3333
_5 = copy _4;
3434
goto -> bb1;
@@ -37,7 +37,7 @@ fn inclusive_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () {
3737
bb1: {
3838
StorageLive(_7);
3939
_6 = &mut _5;
40-
_7 = <RangeInclusive<u32> as iter::range::RangeInclusiveIteratorImpl>::spec_next(move _6) -> [return: bb2, unwind unreachable];
40+
_7 = <std::ops::RangeInclusive<u32> as iter::range::RangeInclusiveIteratorImpl>::spec_next(move _6) -> [return: bb2, unwind unreachable];
4141
}
4242

4343
bb2: {

Diff for: tests/mir-opt/pre-codegen/range_iter.inclusive_loop.PreCodegen.after.panic-unwind.mir

+5-5
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ fn inclusive_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () {
1919
scope 2 {
2020
debug x => _9;
2121
}
22-
scope 5 (inlined iter::range::<impl Iterator for RangeInclusive<u32>>::next) {
22+
scope 5 (inlined iter::range::<impl Iterator for std::ops::RangeInclusive<u32>>::next) {
2323
}
2424
}
25-
scope 3 (inlined RangeInclusive::<u32>::new) {
25+
scope 3 (inlined std::ops::RangeInclusive::<u32>::new) {
2626
}
27-
scope 4 (inlined <RangeInclusive<u32> as IntoIterator>::into_iter) {
27+
scope 4 (inlined <std::ops::RangeInclusive<u32> as IntoIterator>::into_iter) {
2828
}
2929

3030
bb0: {
31-
_4 = RangeInclusive::<u32> { start: copy _1, end: copy _2, exhausted: const false };
31+
_4 = std::ops::RangeInclusive::<u32> { start: copy _1, end: copy _2, exhausted: const false };
3232
StorageLive(_5);
3333
_5 = copy _4;
3434
goto -> bb1;
@@ -37,7 +37,7 @@ fn inclusive_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () {
3737
bb1: {
3838
StorageLive(_7);
3939
_6 = &mut _5;
40-
_7 = <RangeInclusive<u32> as iter::range::RangeInclusiveIteratorImpl>::spec_next(move _6) -> [return: bb2, unwind: bb8];
40+
_7 = <std::ops::RangeInclusive<u32> as iter::range::RangeInclusiveIteratorImpl>::spec_next(move _6) -> [return: bb2, unwind: bb8];
4141
}
4242

4343
bb2: {

Diff for: tests/mir-opt/pre-codegen/range_iter.range_inclusive_iter_next.PreCodegen.after.panic-abort.mir

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// MIR for `range_inclusive_iter_next` after PreCodegen
22

3-
fn range_inclusive_iter_next(_1: &mut RangeInclusive<u32>) -> Option<u32> {
3+
fn range_inclusive_iter_next(_1: &mut std::ops::RangeInclusive<u32>) -> Option<u32> {
44
debug it => _1;
55
let mut _0: std::option::Option<u32>;
6-
scope 1 (inlined iter::range::<impl Iterator for RangeInclusive<u32>>::next) {
6+
scope 1 (inlined iter::range::<impl Iterator for std::ops::RangeInclusive<u32>>::next) {
77
}
88

99
bb0: {
10-
_0 = <RangeInclusive<u32> as iter::range::RangeInclusiveIteratorImpl>::spec_next(move _1) -> [return: bb1, unwind unreachable];
10+
_0 = <std::ops::RangeInclusive<u32> as iter::range::RangeInclusiveIteratorImpl>::spec_next(move _1) -> [return: bb1, unwind unreachable];
1111
}
1212

1313
bb1: {

Diff for: tests/mir-opt/pre-codegen/range_iter.range_inclusive_iter_next.PreCodegen.after.panic-unwind.mir

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// MIR for `range_inclusive_iter_next` after PreCodegen
22

3-
fn range_inclusive_iter_next(_1: &mut RangeInclusive<u32>) -> Option<u32> {
3+
fn range_inclusive_iter_next(_1: &mut std::ops::RangeInclusive<u32>) -> Option<u32> {
44
debug it => _1;
55
let mut _0: std::option::Option<u32>;
6-
scope 1 (inlined iter::range::<impl Iterator for RangeInclusive<u32>>::next) {
6+
scope 1 (inlined iter::range::<impl Iterator for std::ops::RangeInclusive<u32>>::next) {
77
}
88

99
bb0: {
10-
_0 = <RangeInclusive<u32> as iter::range::RangeInclusiveIteratorImpl>::spec_next(move _1) -> [return: bb1, unwind continue];
10+
_0 = <std::ops::RangeInclusive<u32> as iter::range::RangeInclusiveIteratorImpl>::spec_next(move _1) -> [return: bb1, unwind continue];
1111
}
1212

1313
bb1: {

Diff for: tests/ui/const-generics/std/const-generics-range.full.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0741]: `std::ops::Range<usize>` must implement `ConstParamTy` to be used
44
LL | struct _Range<const R: std::ops::Range<usize>>;
55
| ^^^^^^^^^^^^^^^^^^^^^^
66

7-
error[E0741]: `RangeFrom<usize>` must implement `ConstParamTy` to be used as the type of a const generic parameter
7+
error[E0741]: `std::ops::RangeFrom<usize>` must implement `ConstParamTy` to be used as the type of a const generic parameter
88
--> $DIR/const-generics-range.rs:13:28
99
|
1010
LL | struct _RangeFrom<const R: std::ops::RangeFrom<usize>>;
@@ -16,7 +16,7 @@ error[E0741]: `RangeFull` must implement `ConstParamTy` to be used as the type o
1616
LL | struct _RangeFull<const R: std::ops::RangeFull>;
1717
| ^^^^^^^^^^^^^^^^^^^
1818

19-
error[E0741]: `RangeInclusive<usize>` must implement `ConstParamTy` to be used as the type of a const generic parameter
19+
error[E0741]: `std::ops::RangeInclusive<usize>` must implement `ConstParamTy` to be used as the type of a const generic parameter
2020
--> $DIR/const-generics-range.rs:24:33
2121
|
2222
LL | struct _RangeInclusive<const R: std::ops::RangeInclusive<usize>>;

Diff for: tests/ui/const-generics/std/const-generics-range.min.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ help: add `#![feature(adt_const_params)]` to the crate attributes to enable more
1010
LL + #![feature(adt_const_params)]
1111
|
1212

13-
error: `RangeFrom<usize>` is forbidden as the type of a const generic parameter
13+
error: `std::ops::RangeFrom<usize>` is forbidden as the type of a const generic parameter
1414
--> $DIR/const-generics-range.rs:13:28
1515
|
1616
LL | struct _RangeFrom<const R: std::ops::RangeFrom<usize>>;
@@ -34,7 +34,7 @@ help: add `#![feature(adt_const_params)]` to the crate attributes to enable more
3434
LL + #![feature(adt_const_params)]
3535
|
3636

37-
error: `RangeInclusive<usize>` is forbidden as the type of a const generic parameter
37+
error: `std::ops::RangeInclusive<usize>` is forbidden as the type of a const generic parameter
3838
--> $DIR/const-generics-range.rs:24:33
3939
|
4040
LL | struct _RangeInclusive<const R: std::ops::RangeInclusive<usize>>;

Diff for: tests/ui/const-generics/std/const-generics-range.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const RANGE : _Range<{ 0 .. 1000 }> = _Range;
1111

1212
// `RangeFrom` should be usable within const generics:
1313
struct _RangeFrom<const R: std::ops::RangeFrom<usize>>;
14-
//[min]~^ ERROR `RangeFrom<usize>` is forbidden
14+
//[min]~^ ERROR `std::ops::RangeFrom<usize>` is forbidden
1515
const RANGE_FROM : _RangeFrom<{ 0 .. }> = _RangeFrom;
1616

1717
// `RangeFull` should be usable within const generics:
@@ -22,7 +22,7 @@ const RANGE_FULL : _RangeFull<{ .. }> = _RangeFull;
2222
// Regression test for #70155
2323
// `RangeInclusive` should be usable within const generics:
2424
struct _RangeInclusive<const R: std::ops::RangeInclusive<usize>>;
25-
//[min]~^ ERROR `RangeInclusive<usize>` is forbidden
25+
//[min]~^ ERROR `std::ops::RangeInclusive<usize>` is forbidden
2626
const RANGE_INCLUSIVE : _RangeInclusive<{ 0 ..= 999 }> = _RangeInclusive;
2727

2828
// `RangeTo` should be usable within const generics:

Diff for: tests/ui/issues/issue-76191.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ LL | RANGE => {}
2121
| `RANGE` is interpreted as a constant, not a new binding
2222
|
2323
= note: expected type `i32`
24-
found struct `RangeInclusive<i32>`
24+
found struct `std::ops::RangeInclusive<i32>`
2525
help: you may want to move the range into the match block
2626
|
2727
LL | 0..=255 => {}
@@ -43,7 +43,7 @@ LL | RANGE2 => {}
4343
| `RANGE2` is interpreted as a constant, not a new binding
4444
|
4545
= note: expected type `i32`
46-
found struct `RangeInclusive<i32>`
46+
found struct `std::ops::RangeInclusive<i32>`
4747
= note: constants only support matching by type, if you meant to match against a range of values, consider using a range pattern like `min ..= max` in the match block
4848

4949
error: aborting due to 3 previous errors

Diff for: tests/ui/mismatched_types/closure-arg-type-mismatch-issue-45727.current.fixed

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
fn main() {
66
let _ = (-10..=10).find(|x: &i32| x.signum() == 0);
77
//[current]~^ ERROR type mismatch in closure arguments
8-
//[next]~^^ ERROR expected a `FnMut(&<RangeInclusive<{integer}> as Iterator>::Item)` closure, found
8+
//[next]~^^ ERROR expected a `FnMut(&<std::ops::RangeInclusive<{integer}> as Iterator>::Item)` closure, found
99
let _ = (-10..=10).find(|x: &i32| x.signum() == 0);
1010
//[current]~^ ERROR type mismatch in closure arguments
1111
//[next]~^^ ERROR expected `RangeInclusive<{integer}>` to be an iterator that yields `&&i32`, but it yields `{integer}`

Diff for: tests/ui/mismatched_types/closure-arg-type-mismatch-issue-45727.next.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
error[E0277]: expected a `FnMut(&<RangeInclusive<{integer}> as Iterator>::Item)` closure, found `{closure@$DIR/closure-arg-type-mismatch-issue-45727.rs:6:29: 6:37}`
1+
error[E0277]: expected a `FnMut(&<std::ops::RangeInclusive<{integer}> as Iterator>::Item)` closure, found `{closure@$DIR/closure-arg-type-mismatch-issue-45727.rs:6:29: 6:37}`
22
--> $DIR/closure-arg-type-mismatch-issue-45727.rs:6:29
33
|
44
LL | let _ = (-10..=10).find(|x: i32| x.signum() == 0);
5-
| ---- ^^^^^^^^^^^^^^^^^^^^^^^^ expected an `FnMut(&<RangeInclusive<{integer}> as Iterator>::Item)` closure, found `{closure@$DIR/closure-arg-type-mismatch-issue-45727.rs:6:29: 6:37}`
5+
| ---- ^^^^^^^^^^^^^^^^^^^^^^^^ expected an `FnMut(&<std::ops::RangeInclusive<{integer}> as Iterator>::Item)` closure, found `{closure@$DIR/closure-arg-type-mismatch-issue-45727.rs:6:29: 6:37}`
66
| |
77
| required by a bound introduced by this call
88
|
9-
= help: the trait `for<'a> FnMut(&'a <RangeInclusive<{integer}> as Iterator>::Item)` is not implemented for closure `{closure@$DIR/closure-arg-type-mismatch-issue-45727.rs:6:29: 6:37}`
9+
= help: the trait `for<'a> FnMut(&'a <std::ops::RangeInclusive<{integer}> as Iterator>::Item)` is not implemented for closure `{closure@$DIR/closure-arg-type-mismatch-issue-45727.rs:6:29: 6:37}`
1010
= note: expected a closure with arguments `(i32,)`
11-
found a closure with arguments `(&<RangeInclusive<{integer}> as Iterator>::Item,)`
11+
found a closure with arguments `(&<std::ops::RangeInclusive<{integer}> as Iterator>::Item,)`
1212
note: required by a bound in `find`
1313
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
1414

Diff for: tests/ui/mismatched_types/closure-arg-type-mismatch-issue-45727.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
fn main() {
66
let _ = (-10..=10).find(|x: i32| x.signum() == 0);
77
//[current]~^ ERROR type mismatch in closure arguments
8-
//[next]~^^ ERROR expected a `FnMut(&<RangeInclusive<{integer}> as Iterator>::Item)` closure, found
8+
//[next]~^^ ERROR expected a `FnMut(&<std::ops::RangeInclusive<{integer}> as Iterator>::Item)` closure, found
99
let _ = (-10..=10).find(|x: &&&i32| x.signum() == 0);
1010
//[current]~^ ERROR type mismatch in closure arguments
1111
//[next]~^^ ERROR expected `RangeInclusive<{integer}>` to be an iterator that yields `&&i32`, but it yields `{integer}`

Diff for: tests/ui/never_type/issue-52443.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ help: give the `break` a value of the expected type
3131
LL | [(); loop { break 42 }];
3232
| ++
3333

34-
error[E0015]: cannot use `for` loop on `RangeFrom<usize>` in constants
34+
error[E0015]: cannot use `for` loop on `std::ops::RangeFrom<usize>` in constants
3535
--> $DIR/issue-52443.rs:9:21
3636
|
3737
LL | [(); { for _ in 0usize.. {}; 0}];
3838
| ^^^^^^^^
3939
|
4040
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
4141

42-
error[E0015]: cannot use `for` loop on `RangeFrom<usize>` in constants
42+
error[E0015]: cannot use `for` loop on `std::ops::RangeFrom<usize>` in constants
4343
--> $DIR/issue-52443.rs:9:21
4444
|
4545
LL | [(); { for _ in 0usize.. {}; 0}];

Diff for: tests/ui/range/issue-54505-no-literals.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ LL | take_range(std::ops::RangeFrom { start: 1 });
4747
| arguments to this function are incorrect
4848
|
4949
= note: expected reference `&_`
50-
found struct `RangeFrom<{integer}>`
50+
found struct `std::ops::RangeFrom<{integer}>`
5151
note: function defined here
5252
--> $DIR/issue-54505-no-literals.rs:12:4
5353
|
@@ -67,7 +67,7 @@ LL | take_range(::std::ops::RangeFrom { start: 1 });
6767
| arguments to this function are incorrect
6868
|
6969
= note: expected reference `&_`
70-
found struct `RangeFrom<{integer}>`
70+
found struct `std::ops::RangeFrom<{integer}>`
7171
note: function defined here
7272
--> $DIR/issue-54505-no-literals.rs:12:4
7373
|
@@ -127,7 +127,7 @@ LL | take_range(std::ops::RangeInclusive::new(0, 1));
127127
| arguments to this function are incorrect
128128
|
129129
= note: expected reference `&_`
130-
found struct `RangeInclusive<{integer}>`
130+
found struct `std::ops::RangeInclusive<{integer}>`
131131
note: function defined here
132132
--> $DIR/issue-54505-no-literals.rs:12:4
133133
|
@@ -147,7 +147,7 @@ LL | take_range(::std::ops::RangeInclusive::new(0, 1));
147147
| arguments to this function are incorrect
148148
|
149149
= note: expected reference `&_`
150-
found struct `RangeInclusive<{integer}>`
150+
found struct `std::ops::RangeInclusive<{integer}>`
151151
note: function defined here
152152
--> $DIR/issue-54505-no-literals.rs:12:4
153153
|

Diff for: tests/ui/range/issue-54505.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ LL | take_range(1..);
2727
| arguments to this function are incorrect
2828
|
2929
= note: expected reference `&_`
30-
found struct `RangeFrom<{integer}>`
30+
found struct `std::ops::RangeFrom<{integer}>`
3131
note: function defined here
3232
--> $DIR/issue-54505.rs:10:4
3333
|
@@ -72,7 +72,7 @@ LL | take_range(0..=1);
7272
| arguments to this function are incorrect
7373
|
7474
= note: expected reference `&_`
75-
found struct `RangeInclusive<{integer}>`
75+
found struct `std::ops::RangeInclusive<{integer}>`
7676
note: function defined here
7777
--> $DIR/issue-54505.rs:10:4
7878
|

Diff for: tests/ui/range/range-1.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ LL | let range = *arr..;
3030
| ^^^^ doesn't have a size known at compile-time
3131
|
3232
= help: the trait `Sized` is not implemented for `[{integer}]`
33-
note: required by an implicit `Sized` bound in `RangeFrom`
33+
note: required by an implicit `Sized` bound in `std::ops::RangeFrom`
3434
--> $SRC_DIR/core/src/ops/range.rs:LL:COL
3535

3636
error: aborting due to 3 previous errors

Diff for: tests/ui/suggestions/unnecessary_dot_for_floating_point_literal.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ LL | let _: f64 = 1..;
2222
| expected due to this
2323
|
2424
= note: expected type `f64`
25-
found struct `RangeFrom<{integer}>`
25+
found struct `std::ops::RangeFrom<{integer}>`
2626
help: remove the unnecessary `.` operator for a floating point literal
2727
|
2828
LL | let _: f64 = 1.;

0 commit comments

Comments
 (0)