Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c7bf3a0

Browse files
authoredFeb 4, 2025··
Unrolled build for rust-lang#136167
Rollup merge of rust-lang#136167 - pitaj:new_range, r=Nadrieril Implement unstable `new_range` feature Switches `a..b`, `a..`, and `a..=b` to resolve to the new range types. For rust-lang/rfcs#3550 Tracking issue rust-lang#123741 also adds the re-export that was missed in the original implementation of `new_range_api`
2 parents 019fc4d + f530a29 commit c7bf3a0

29 files changed

+252
-54
lines changed
 

‎compiler/rustc_ast_lowering/src/expr.rs

+28-7
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
284284
ExprKind::Index(el, er, brackets_span) => {
285285
hir::ExprKind::Index(self.lower_expr(el), self.lower_expr(er), *brackets_span)
286286
}
287-
ExprKind::Range(Some(e1), Some(e2), RangeLimits::Closed) => {
288-
self.lower_expr_range_closed(e.span, e1, e2)
289-
}
290287
ExprKind::Range(e1, e2, lims) => {
291288
self.lower_expr_range(e.span, e1.as_deref(), e2.as_deref(), *lims)
292289
}
@@ -1512,15 +1509,39 @@ impl<'hir> LoweringContext<'_, 'hir> {
15121509

15131510
let lang_item = match (e1, e2, lims) {
15141511
(None, None, HalfOpen) => hir::LangItem::RangeFull,
1515-
(Some(..), None, HalfOpen) => hir::LangItem::RangeFrom,
1512+
(Some(..), None, HalfOpen) => {
1513+
if self.tcx.features().new_range() {
1514+
hir::LangItem::RangeFromCopy
1515+
} else {
1516+
hir::LangItem::RangeFrom
1517+
}
1518+
}
15161519
(None, Some(..), HalfOpen) => hir::LangItem::RangeTo,
1517-
(Some(..), Some(..), HalfOpen) => hir::LangItem::Range,
1520+
(Some(..), Some(..), HalfOpen) => {
1521+
if self.tcx.features().new_range() {
1522+
hir::LangItem::RangeCopy
1523+
} else {
1524+
hir::LangItem::Range
1525+
}
1526+
}
15181527
(None, Some(..), Closed) => hir::LangItem::RangeToInclusive,
1519-
(Some(..), Some(..), Closed) => unreachable!(),
1528+
(Some(e1), Some(e2), Closed) => {
1529+
if self.tcx.features().new_range() {
1530+
hir::LangItem::RangeInclusiveCopy
1531+
} else {
1532+
return self.lower_expr_range_closed(span, e1, e2);
1533+
}
1534+
}
15201535
(start, None, Closed) => {
15211536
self.dcx().emit_err(InclusiveRangeWithNoEnd { span });
15221537
match start {
1523-
Some(..) => hir::LangItem::RangeFrom,
1538+
Some(..) => {
1539+
if self.tcx.features().new_range() {
1540+
hir::LangItem::RangeFromCopy
1541+
} else {
1542+
hir::LangItem::RangeFrom
1543+
}
1544+
}
15241545
None => hir::LangItem::RangeFull,
15251546
}
15261547
}

‎compiler/rustc_feature/src/unstable.rs

+2
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,8 @@ declare_features! (
570570
(unstable, never_type, "1.13.0", Some(35121)),
571571
/// Allows diverging expressions to fall back to `!` rather than `()`.
572572
(unstable, never_type_fallback, "1.41.0", Some(65992)),
573+
/// Switch `..` syntax to use the new (`Copy + IntoIterator`) range types.
574+
(unstable, new_range, "CURRENT_RUSTC_VERSION", Some(123741)),
573575
/// Allows `#![no_core]`.
574576
(unstable, no_core, "1.3.0", Some(29639)),
575577
/// Allows the use of `no_sanitize` attribute.

‎compiler/rustc_hir/src/hir.rs

+40-1
Original file line numberDiff line numberDiff line change
@@ -2313,6 +2313,18 @@ impl Expr<'_> {
23132313
[val2],
23142314
StructTailExpr::None,
23152315
),
2316+
)
2317+
| (
2318+
ExprKind::Struct(
2319+
QPath::LangItem(LangItem::RangeFromCopy, _),
2320+
[val1],
2321+
StructTailExpr::None,
2322+
),
2323+
ExprKind::Struct(
2324+
QPath::LangItem(LangItem::RangeFromCopy, _),
2325+
[val2],
2326+
StructTailExpr::None,
2327+
),
23162328
) => val1.expr.equivalent_for_indexing(val2.expr),
23172329
(
23182330
ExprKind::Struct(
@@ -2325,6 +2337,30 @@ impl Expr<'_> {
23252337
[val2, val4],
23262338
StructTailExpr::None,
23272339
),
2340+
)
2341+
| (
2342+
ExprKind::Struct(
2343+
QPath::LangItem(LangItem::RangeCopy, _),
2344+
[val1, val3],
2345+
StructTailExpr::None,
2346+
),
2347+
ExprKind::Struct(
2348+
QPath::LangItem(LangItem::RangeCopy, _),
2349+
[val2, val4],
2350+
StructTailExpr::None,
2351+
),
2352+
)
2353+
| (
2354+
ExprKind::Struct(
2355+
QPath::LangItem(LangItem::RangeInclusiveCopy, _),
2356+
[val1, val3],
2357+
StructTailExpr::None,
2358+
),
2359+
ExprKind::Struct(
2360+
QPath::LangItem(LangItem::RangeInclusiveCopy, _),
2361+
[val2, val4],
2362+
StructTailExpr::None,
2363+
),
23282364
) => {
23292365
val1.expr.equivalent_for_indexing(val2.expr)
23302366
&& val3.expr.equivalent_for_indexing(val4.expr)
@@ -2354,7 +2390,10 @@ pub fn is_range_literal(expr: &Expr<'_>) -> bool {
23542390
| LangItem::RangeTo
23552391
| LangItem::RangeFrom
23562392
| LangItem::RangeFull
2357-
| LangItem::RangeToInclusive,
2393+
| LangItem::RangeToInclusive
2394+
| LangItem::RangeCopy
2395+
| LangItem::RangeFromCopy
2396+
| LangItem::RangeInclusiveCopy,
23582397
..
23592398
)
23602399
),

‎compiler/rustc_hir/src/lang_items.rs

+5
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,11 @@ language_item_table! {
416416
RangeToInclusive, sym::RangeToInclusive, range_to_inclusive_struct, Target::Struct, GenericRequirement::None;
417417
RangeTo, sym::RangeTo, range_to_struct, Target::Struct, GenericRequirement::None;
418418

419+
// `new_range` types that are `Copy + IntoIterator`
420+
RangeFromCopy, sym::RangeFromCopy, range_from_copy_struct, Target::Struct, GenericRequirement::None;
421+
RangeCopy, sym::RangeCopy, range_copy_struct, Target::Struct, GenericRequirement::None;
422+
RangeInclusiveCopy, sym::RangeInclusiveCopy, range_inclusive_copy_struct, Target::Struct, GenericRequirement::None;
423+
419424
String, sym::String, string, Target::Struct, GenericRequirement::None;
420425
CStr, sym::CStr, c_str, Target::Struct, GenericRequirement::None;
421426
}

‎compiler/rustc_hir_typeck/src/method/suggest.rs

+4
Original file line numberDiff line numberDiff line change
@@ -2395,6 +2395,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
23952395
let lang_item = match parent_expr.kind {
23962396
ExprKind::Struct(qpath, _, _) => match *qpath {
23972397
QPath::LangItem(LangItem::Range, ..) => Some(LangItem::Range),
2398+
QPath::LangItem(LangItem::RangeCopy, ..) => Some(LangItem::RangeCopy),
2399+
QPath::LangItem(LangItem::RangeInclusiveCopy, ..) => {
2400+
Some(LangItem::RangeInclusiveCopy)
2401+
}
23982402
QPath::LangItem(LangItem::RangeTo, ..) => Some(LangItem::RangeTo),
23992403
QPath::LangItem(LangItem::RangeToInclusive, ..) => {
24002404
Some(LangItem::RangeToInclusive)

‎compiler/rustc_span/src/symbol.rs

+4
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,12 @@ symbols! {
294294
ProceduralMasqueradeDummyType,
295295
Range,
296296
RangeBounds,
297+
RangeCopy,
297298
RangeFrom,
299+
RangeFromCopy,
298300
RangeFull,
299301
RangeInclusive,
302+
RangeInclusiveCopy,
300303
RangeTo,
301304
RangeToInclusive,
302305
Rc,
@@ -1364,6 +1367,7 @@ symbols! {
13641367
new_lower_hex,
13651368
new_octal,
13661369
new_pointer,
1370+
new_range,
13671371
new_unchecked,
13681372
new_upper_exp,
13691373
new_upper_hex,

‎library/core/src/range.rs

+3
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ pub use crate::ops::{Bound, OneSidedRange, RangeBounds, RangeFull, RangeTo, Rang
4848
/// assert_eq!(Range::from(3..5), Range { start: 3, end: 5 });
4949
/// assert_eq!(3 + 4 + 5, Range::from(3..6).into_iter().sum());
5050
/// ```
51+
#[cfg_attr(not(bootstrap), lang = "RangeCopy")]
5152
#[derive(Clone, Copy, Default, PartialEq, Eq, Hash)]
5253
#[unstable(feature = "new_range_api", issue = "125687")]
5354
pub struct Range<Idx> {
@@ -205,6 +206,7 @@ impl<T> From<legacy::Range<T>> for Range<T> {
205206
/// assert_eq!(RangeInclusive::from(3..=5), RangeInclusive { start: 3, end: 5 });
206207
/// assert_eq!(3 + 4 + 5, RangeInclusive::from(3..=5).into_iter().sum());
207208
/// ```
209+
#[cfg_attr(not(bootstrap), lang = "RangeInclusiveCopy")]
208210
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
209211
#[unstable(feature = "new_range_api", issue = "125687")]
210212
pub struct RangeInclusive<Idx> {
@@ -388,6 +390,7 @@ impl<T> From<legacy::RangeInclusive<T>> for RangeInclusive<T> {
388390
/// assert_eq!(RangeFrom::from(2..), core::range::RangeFrom { start: 2 });
389391
/// assert_eq!(2 + 3 + 4, RangeFrom::from(2..).into_iter().take(3).sum());
390392
/// ```
393+
#[cfg_attr(not(bootstrap), lang = "RangeFromCopy")]
391394
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
392395
#[unstable(feature = "new_range_api", issue = "125687")]
393396
pub struct RangeFrom<Idx> {

‎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")]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# `new_range`
2+
3+
The tracking issue for this feature is: [#123741]
4+
5+
[#123741]: https://github.com/rust-lang/rust/issues/123741
6+
7+
---
8+
9+
Switch the syntaxes `a..`, `a..b`, and `a..=b` to resolve the new range types.

‎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: {

‎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: {

‎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: {

‎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: {

‎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>>;

‎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>>;

‎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:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#![feature(new_range_api)]
2+
3+
fn main() {
4+
let a: core::range::RangeFrom<u8> = 1..;
5+
//~^ mismatched types
6+
let b: core::range::Range<u8> = 2..3;
7+
//~^ mismatched types
8+
let c: core::range::RangeInclusive<u8> = 4..=5;
9+
//~^ mismatched types
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/feature-gate-new_range.rs:4:41
3+
|
4+
LL | let a: core::range::RangeFrom<u8> = 1..;
5+
| -------------------------- ^^^ expected `RangeFrom<u8>`, found `RangeFrom<{integer}>`
6+
| |
7+
| expected due to this
8+
|
9+
= note: expected struct `std::range::RangeFrom<u8>`
10+
found struct `std::ops::RangeFrom<{integer}>`
11+
help: call `Into::into` on this expression to convert `std::ops::RangeFrom<{integer}>` into `std::range::RangeFrom<u8>`
12+
|
13+
LL | let a: core::range::RangeFrom<u8> = 1...into();
14+
| +++++++
15+
16+
error[E0308]: mismatched types
17+
--> $DIR/feature-gate-new_range.rs:6:37
18+
|
19+
LL | let b: core::range::Range<u8> = 2..3;
20+
| ---------------------- ^^^^ expected `Range<u8>`, found `Range<{integer}>`
21+
| |
22+
| expected due to this
23+
|
24+
= note: expected struct `std::range::Range<u8>`
25+
found struct `std::ops::Range<{integer}>`
26+
help: call `Into::into` on this expression to convert `std::ops::Range<{integer}>` into `std::range::Range<u8>`
27+
|
28+
LL | let b: core::range::Range<u8> = 2..3.into();
29+
| +++++++
30+
31+
error[E0308]: mismatched types
32+
--> $DIR/feature-gate-new_range.rs:8:46
33+
|
34+
LL | let c: core::range::RangeInclusive<u8> = 4..=5;
35+
| ------------------------------- ^^^^^ expected `RangeInclusive<u8>`, found `RangeInclusive<{integer}>`
36+
| |
37+
| expected due to this
38+
|
39+
= note: expected struct `std::range::RangeInclusive<u8>`
40+
found struct `std::ops::RangeInclusive<{integer}>`
41+
help: call `Into::into` on this expression to convert `std::ops::RangeInclusive<{integer}>` into `std::range::RangeInclusive<u8>`
42+
|
43+
LL | let c: core::range::RangeInclusive<u8> = 4..=5.into();
44+
| +++++++
45+
46+
error: aborting due to 3 previous errors
47+
48+
For more information about this error, try `rustc --explain E0308`.

‎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

‎tests/ui/mismatched_types/closure-arg-type-mismatch-issue-45727.current.fixed

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
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}`
12-
//[next]~| ERROR expected a `FnMut(&<RangeInclusive<{integer}> as Iterator>::Item)` closure, found
12+
//[next]~| ERROR expected a `FnMut(&<std::ops::RangeInclusive<{integer}> as Iterator>::Item)` closure, found
1313
}

‎tests/ui/mismatched_types/closure-arg-type-mismatch-issue-45727.next.stderr

+8-8
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

@@ -18,17 +18,17 @@ error[E0271]: expected `RangeInclusive<{integer}>` to be an iterator that yields
1818
LL | let _ = (-10..=10).find(|x: &&&i32| x.signum() == 0);
1919
| ^^^^ expected `&&i32`, found integer
2020

21-
error[E0277]: expected a `FnMut(&<RangeInclusive<{integer}> as Iterator>::Item)` closure, found `{closure@$DIR/closure-arg-type-mismatch-issue-45727.rs:9:29: 9:40}`
21+
error[E0277]: expected a `FnMut(&<std::ops::RangeInclusive<{integer}> as Iterator>::Item)` closure, found `{closure@$DIR/closure-arg-type-mismatch-issue-45727.rs:9:29: 9:40}`
2222
--> $DIR/closure-arg-type-mismatch-issue-45727.rs:9:29
2323
|
2424
LL | let _ = (-10..=10).find(|x: &&&i32| x.signum() == 0);
25-
| ---- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected an `FnMut(&<RangeInclusive<{integer}> as Iterator>::Item)` closure, found `{closure@$DIR/closure-arg-type-mismatch-issue-45727.rs:9:29: 9:40}`
25+
| ---- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected an `FnMut(&<std::ops::RangeInclusive<{integer}> as Iterator>::Item)` closure, found `{closure@$DIR/closure-arg-type-mismatch-issue-45727.rs:9:29: 9:40}`
2626
| |
2727
| required by a bound introduced by this call
2828
|
29-
= 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:9:29: 9:40}`
29+
= 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:9:29: 9:40}`
3030
= note: expected a closure with arguments `(&&&i32,)`
31-
found a closure with arguments `(&<RangeInclusive<{integer}> as Iterator>::Item,)`
31+
found a closure with arguments `(&<std::ops::RangeInclusive<{integer}> as Iterator>::Item,)`
3232
note: required by a bound in `find`
3333
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
3434

‎tests/ui/mismatched_types/closure-arg-type-mismatch-issue-45727.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
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}`
12-
//[next]~| ERROR expected a `FnMut(&<RangeInclusive<{integer}> as Iterator>::Item)` closure, found
12+
//[next]~| ERROR expected a `FnMut(&<std::ops::RangeInclusive<{integer}> as Iterator>::Item)` closure, found
1313
}

‎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}];

‎tests/ui/new-range/disabled.rs

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//@ check-pass
2+
3+
#![feature(new_range_api)]
4+
5+
fn main() {
6+
// Unchanged
7+
let a: core::range::RangeFull = ..;
8+
let b: core::range::RangeTo<u8> = ..2;
9+
let c: core::range::RangeToInclusive<u8> = ..=3;
10+
11+
let _: core::ops::RangeFull = a;
12+
let _: core::ops::RangeTo<u8> = b;
13+
let _: core::ops::RangeToInclusive<u8> = c;
14+
15+
// Changed
16+
let a: core::range::legacy::RangeFrom<u8> = 1..;
17+
let b: core::range::legacy::Range<u8> = 2..3;
18+
let c: core::range::legacy::RangeInclusive<u8> = 4..=5;
19+
20+
let a: core::ops::RangeFrom<u8> = a;
21+
let b: core::ops::Range<u8> = b;
22+
let c: core::ops::RangeInclusive<u8> = c;
23+
24+
let _: core::ops::RangeFrom<u8> = a.into_iter();
25+
let _: core::ops::Range<u8> = b.into_iter();
26+
let _: core::ops::RangeInclusive<u8> = c.into_iter();
27+
}

‎tests/ui/new-range/enabled.rs

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//@ check-pass
2+
3+
#![feature(new_range_api)]
4+
#![feature(new_range)]
5+
6+
fn main() {
7+
// Unchanged
8+
let a: core::range::RangeFull = ..;
9+
let b: core::range::RangeTo<u8> = ..2;
10+
let c: core::range::RangeToInclusive<u8> = ..=3;
11+
12+
let _: core::ops::RangeFull = a;
13+
let _: core::ops::RangeTo<u8> = b;
14+
let _: core::ops::RangeToInclusive<u8> = c;
15+
16+
// Changed
17+
let a: core::range::RangeFrom<u8> = 1..;
18+
let b: core::range::Range<u8> = 2..3;
19+
let c: core::range::RangeInclusive<u8> = 4..=5;
20+
21+
let _: core::range::IterRangeFrom<u8> = a.into_iter();
22+
let _: core::range::IterRange<u8> = b.into_iter();
23+
let _: core::range::IterRangeInclusive<u8> = c.into_iter();
24+
}

‎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
|

‎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
|

‎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

‎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)
Please sign in to comment.