Rollup merge of #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 #123741

also adds the re-export that was missed in the original implementation of `new_range_api`
This commit is contained in:
Jacob Pratt 2025-02-04 05:36:52 -05:00 committed by GitHub
commit d31e137d6a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
29 changed files with 252 additions and 54 deletions

View file

@ -284,9 +284,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
ExprKind::Index(el, er, brackets_span) => { ExprKind::Index(el, er, brackets_span) => {
hir::ExprKind::Index(self.lower_expr(el), self.lower_expr(er), *brackets_span) hir::ExprKind::Index(self.lower_expr(el), self.lower_expr(er), *brackets_span)
} }
ExprKind::Range(Some(e1), Some(e2), RangeLimits::Closed) => {
self.lower_expr_range_closed(e.span, e1, e2)
}
ExprKind::Range(e1, e2, lims) => { ExprKind::Range(e1, e2, lims) => {
self.lower_expr_range(e.span, e1.as_deref(), e2.as_deref(), *lims) self.lower_expr_range(e.span, e1.as_deref(), e2.as_deref(), *lims)
} }
@ -1512,15 +1509,39 @@ impl<'hir> LoweringContext<'_, 'hir> {
let lang_item = match (e1, e2, lims) { let lang_item = match (e1, e2, lims) {
(None, None, HalfOpen) => hir::LangItem::RangeFull, (None, None, HalfOpen) => hir::LangItem::RangeFull,
(Some(..), None, HalfOpen) => hir::LangItem::RangeFrom, (Some(..), None, HalfOpen) => {
if self.tcx.features().new_range() {
hir::LangItem::RangeFromCopy
} else {
hir::LangItem::RangeFrom
}
}
(None, Some(..), HalfOpen) => hir::LangItem::RangeTo, (None, Some(..), HalfOpen) => hir::LangItem::RangeTo,
(Some(..), Some(..), HalfOpen) => hir::LangItem::Range, (Some(..), Some(..), HalfOpen) => {
if self.tcx.features().new_range() {
hir::LangItem::RangeCopy
} else {
hir::LangItem::Range
}
}
(None, Some(..), Closed) => hir::LangItem::RangeToInclusive, (None, Some(..), Closed) => hir::LangItem::RangeToInclusive,
(Some(..), Some(..), Closed) => unreachable!(), (Some(e1), Some(e2), Closed) => {
if self.tcx.features().new_range() {
hir::LangItem::RangeInclusiveCopy
} else {
return self.lower_expr_range_closed(span, e1, e2);
}
}
(start, None, Closed) => { (start, None, Closed) => {
self.dcx().emit_err(InclusiveRangeWithNoEnd { span }); self.dcx().emit_err(InclusiveRangeWithNoEnd { span });
match start { match start {
Some(..) => hir::LangItem::RangeFrom, Some(..) => {
if self.tcx.features().new_range() {
hir::LangItem::RangeFromCopy
} else {
hir::LangItem::RangeFrom
}
}
None => hir::LangItem::RangeFull, None => hir::LangItem::RangeFull,
} }
} }

View file

@ -570,6 +570,8 @@ declare_features! (
(unstable, never_type, "1.13.0", Some(35121)), (unstable, never_type, "1.13.0", Some(35121)),
/// Allows diverging expressions to fall back to `!` rather than `()`. /// Allows diverging expressions to fall back to `!` rather than `()`.
(unstable, never_type_fallback, "1.41.0", Some(65992)), (unstable, never_type_fallback, "1.41.0", Some(65992)),
/// Switch `..` syntax to use the new (`Copy + IntoIterator`) range types.
(unstable, new_range, "CURRENT_RUSTC_VERSION", Some(123741)),
/// Allows `#![no_core]`. /// Allows `#![no_core]`.
(unstable, no_core, "1.3.0", Some(29639)), (unstable, no_core, "1.3.0", Some(29639)),
/// Allows the use of `no_sanitize` attribute. /// Allows the use of `no_sanitize` attribute.

View file

@ -2313,6 +2313,18 @@ impl Expr<'_> {
[val2], [val2],
StructTailExpr::None, StructTailExpr::None,
), ),
)
| (
ExprKind::Struct(
QPath::LangItem(LangItem::RangeFromCopy, _),
[val1],
StructTailExpr::None,
),
ExprKind::Struct(
QPath::LangItem(LangItem::RangeFromCopy, _),
[val2],
StructTailExpr::None,
),
) => val1.expr.equivalent_for_indexing(val2.expr), ) => val1.expr.equivalent_for_indexing(val2.expr),
( (
ExprKind::Struct( ExprKind::Struct(
@ -2325,6 +2337,30 @@ impl Expr<'_> {
[val2, val4], [val2, val4],
StructTailExpr::None, StructTailExpr::None,
), ),
)
| (
ExprKind::Struct(
QPath::LangItem(LangItem::RangeCopy, _),
[val1, val3],
StructTailExpr::None,
),
ExprKind::Struct(
QPath::LangItem(LangItem::RangeCopy, _),
[val2, val4],
StructTailExpr::None,
),
)
| (
ExprKind::Struct(
QPath::LangItem(LangItem::RangeInclusiveCopy, _),
[val1, val3],
StructTailExpr::None,
),
ExprKind::Struct(
QPath::LangItem(LangItem::RangeInclusiveCopy, _),
[val2, val4],
StructTailExpr::None,
),
) => { ) => {
val1.expr.equivalent_for_indexing(val2.expr) val1.expr.equivalent_for_indexing(val2.expr)
&& val3.expr.equivalent_for_indexing(val4.expr) && val3.expr.equivalent_for_indexing(val4.expr)
@ -2354,7 +2390,10 @@ pub fn is_range_literal(expr: &Expr<'_>) -> bool {
| LangItem::RangeTo | LangItem::RangeTo
| LangItem::RangeFrom | LangItem::RangeFrom
| LangItem::RangeFull | LangItem::RangeFull
| LangItem::RangeToInclusive, | LangItem::RangeToInclusive
| LangItem::RangeCopy
| LangItem::RangeFromCopy
| LangItem::RangeInclusiveCopy,
.. ..
) )
), ),

View file

@ -416,6 +416,11 @@ language_item_table! {
RangeToInclusive, sym::RangeToInclusive, range_to_inclusive_struct, Target::Struct, GenericRequirement::None; RangeToInclusive, sym::RangeToInclusive, range_to_inclusive_struct, Target::Struct, GenericRequirement::None;
RangeTo, sym::RangeTo, range_to_struct, Target::Struct, GenericRequirement::None; RangeTo, sym::RangeTo, range_to_struct, Target::Struct, GenericRequirement::None;
// `new_range` types that are `Copy + IntoIterator`
RangeFromCopy, sym::RangeFromCopy, range_from_copy_struct, Target::Struct, GenericRequirement::None;
RangeCopy, sym::RangeCopy, range_copy_struct, Target::Struct, GenericRequirement::None;
RangeInclusiveCopy, sym::RangeInclusiveCopy, range_inclusive_copy_struct, Target::Struct, GenericRequirement::None;
String, sym::String, string, Target::Struct, GenericRequirement::None; String, sym::String, string, Target::Struct, GenericRequirement::None;
CStr, sym::CStr, c_str, Target::Struct, GenericRequirement::None; CStr, sym::CStr, c_str, Target::Struct, GenericRequirement::None;
} }

View file

@ -2395,6 +2395,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let lang_item = match parent_expr.kind { let lang_item = match parent_expr.kind {
ExprKind::Struct(qpath, _, _) => match *qpath { ExprKind::Struct(qpath, _, _) => match *qpath {
QPath::LangItem(LangItem::Range, ..) => Some(LangItem::Range), QPath::LangItem(LangItem::Range, ..) => Some(LangItem::Range),
QPath::LangItem(LangItem::RangeCopy, ..) => Some(LangItem::RangeCopy),
QPath::LangItem(LangItem::RangeInclusiveCopy, ..) => {
Some(LangItem::RangeInclusiveCopy)
}
QPath::LangItem(LangItem::RangeTo, ..) => Some(LangItem::RangeTo), QPath::LangItem(LangItem::RangeTo, ..) => Some(LangItem::RangeTo),
QPath::LangItem(LangItem::RangeToInclusive, ..) => { QPath::LangItem(LangItem::RangeToInclusive, ..) => {
Some(LangItem::RangeToInclusive) Some(LangItem::RangeToInclusive)

View file

@ -294,9 +294,12 @@ symbols! {
ProceduralMasqueradeDummyType, ProceduralMasqueradeDummyType,
Range, Range,
RangeBounds, RangeBounds,
RangeCopy,
RangeFrom, RangeFrom,
RangeFromCopy,
RangeFull, RangeFull,
RangeInclusive, RangeInclusive,
RangeInclusiveCopy,
RangeTo, RangeTo,
RangeToInclusive, RangeToInclusive,
Rc, Rc,
@ -1364,6 +1367,7 @@ symbols! {
new_lower_hex, new_lower_hex,
new_octal, new_octal,
new_pointer, new_pointer,
new_range,
new_unchecked, new_unchecked,
new_upper_exp, new_upper_exp,
new_upper_hex, new_upper_hex,

View file

@ -48,6 +48,7 @@ pub use crate::ops::{Bound, OneSidedRange, RangeBounds, RangeFull, RangeTo, Rang
/// assert_eq!(Range::from(3..5), Range { start: 3, end: 5 }); /// assert_eq!(Range::from(3..5), Range { start: 3, end: 5 });
/// assert_eq!(3 + 4 + 5, Range::from(3..6).into_iter().sum()); /// assert_eq!(3 + 4 + 5, Range::from(3..6).into_iter().sum());
/// ``` /// ```
#[cfg_attr(not(bootstrap), lang = "RangeCopy")]
#[derive(Clone, Copy, Default, PartialEq, Eq, Hash)] #[derive(Clone, Copy, Default, PartialEq, Eq, Hash)]
#[unstable(feature = "new_range_api", issue = "125687")] #[unstable(feature = "new_range_api", issue = "125687")]
pub struct Range<Idx> { pub struct Range<Idx> {
@ -205,6 +206,7 @@ impl<T> From<legacy::Range<T>> for Range<T> {
/// assert_eq!(RangeInclusive::from(3..=5), RangeInclusive { start: 3, end: 5 }); /// assert_eq!(RangeInclusive::from(3..=5), RangeInclusive { start: 3, end: 5 });
/// assert_eq!(3 + 4 + 5, RangeInclusive::from(3..=5).into_iter().sum()); /// assert_eq!(3 + 4 + 5, RangeInclusive::from(3..=5).into_iter().sum());
/// ``` /// ```
#[cfg_attr(not(bootstrap), lang = "RangeInclusiveCopy")]
#[derive(Clone, Copy, PartialEq, Eq, Hash)] #[derive(Clone, Copy, PartialEq, Eq, Hash)]
#[unstable(feature = "new_range_api", issue = "125687")] #[unstable(feature = "new_range_api", issue = "125687")]
pub struct RangeInclusive<Idx> { pub struct RangeInclusive<Idx> {
@ -388,6 +390,7 @@ impl<T> From<legacy::RangeInclusive<T>> for RangeInclusive<T> {
/// assert_eq!(RangeFrom::from(2..), core::range::RangeFrom { start: 2 }); /// assert_eq!(RangeFrom::from(2..), core::range::RangeFrom { start: 2 });
/// assert_eq!(2 + 3 + 4, RangeFrom::from(2..).into_iter().take(3).sum()); /// assert_eq!(2 + 3 + 4, RangeFrom::from(2..).into_iter().take(3).sum());
/// ``` /// ```
#[cfg_attr(not(bootstrap), lang = "RangeFromCopy")]
#[derive(Clone, Copy, PartialEq, Eq, Hash)] #[derive(Clone, Copy, PartialEq, Eq, Hash)]
#[unstable(feature = "new_range_api", issue = "125687")] #[unstable(feature = "new_range_api", issue = "125687")]
pub struct RangeFrom<Idx> { pub struct RangeFrom<Idx> {

View file

@ -530,6 +530,8 @@ pub use core::option;
pub use core::pin; pub use core::pin;
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
pub use core::ptr; pub use core::ptr;
#[unstable(feature = "new_range_api", issue = "125687")]
pub use core::range;
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
pub use core::result; pub use core::result;
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]

View file

@ -0,0 +1,9 @@
# `new_range`
The tracking issue for this feature is: [#123741]
[#123741]: https://github.com/rust-lang/rust/issues/123741
---
Switch the syntaxes `a..`, `a..b`, and `a..=b` to resolve the new range types.

View file

@ -19,16 +19,16 @@ fn inclusive_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () {
scope 2 { scope 2 {
debug x => _9; debug x => _9;
} }
scope 5 (inlined iter::range::<impl Iterator for RangeInclusive<u32>>::next) { scope 5 (inlined iter::range::<impl Iterator for std::ops::RangeInclusive<u32>>::next) {
} }
} }
scope 3 (inlined RangeInclusive::<u32>::new) { scope 3 (inlined std::ops::RangeInclusive::<u32>::new) {
} }
scope 4 (inlined <RangeInclusive<u32> as IntoIterator>::into_iter) { scope 4 (inlined <std::ops::RangeInclusive<u32> as IntoIterator>::into_iter) {
} }
bb0: { bb0: {
_4 = RangeInclusive::<u32> { start: copy _1, end: copy _2, exhausted: const false }; _4 = std::ops::RangeInclusive::<u32> { start: copy _1, end: copy _2, exhausted: const false };
StorageLive(_5); StorageLive(_5);
_5 = copy _4; _5 = copy _4;
goto -> bb1; goto -> bb1;
@ -37,7 +37,7 @@ fn inclusive_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () {
bb1: { bb1: {
StorageLive(_7); StorageLive(_7);
_6 = &mut _5; _6 = &mut _5;
_7 = <RangeInclusive<u32> as iter::range::RangeInclusiveIteratorImpl>::spec_next(move _6) -> [return: bb2, unwind unreachable]; _7 = <std::ops::RangeInclusive<u32> as iter::range::RangeInclusiveIteratorImpl>::spec_next(move _6) -> [return: bb2, unwind unreachable];
} }
bb2: { bb2: {

View file

@ -19,16 +19,16 @@ fn inclusive_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () {
scope 2 { scope 2 {
debug x => _9; debug x => _9;
} }
scope 5 (inlined iter::range::<impl Iterator for RangeInclusive<u32>>::next) { scope 5 (inlined iter::range::<impl Iterator for std::ops::RangeInclusive<u32>>::next) {
} }
} }
scope 3 (inlined RangeInclusive::<u32>::new) { scope 3 (inlined std::ops::RangeInclusive::<u32>::new) {
} }
scope 4 (inlined <RangeInclusive<u32> as IntoIterator>::into_iter) { scope 4 (inlined <std::ops::RangeInclusive<u32> as IntoIterator>::into_iter) {
} }
bb0: { bb0: {
_4 = RangeInclusive::<u32> { start: copy _1, end: copy _2, exhausted: const false }; _4 = std::ops::RangeInclusive::<u32> { start: copy _1, end: copy _2, exhausted: const false };
StorageLive(_5); StorageLive(_5);
_5 = copy _4; _5 = copy _4;
goto -> bb1; goto -> bb1;
@ -37,7 +37,7 @@ fn inclusive_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () {
bb1: { bb1: {
StorageLive(_7); StorageLive(_7);
_6 = &mut _5; _6 = &mut _5;
_7 = <RangeInclusive<u32> as iter::range::RangeInclusiveIteratorImpl>::spec_next(move _6) -> [return: bb2, unwind: bb8]; _7 = <std::ops::RangeInclusive<u32> as iter::range::RangeInclusiveIteratorImpl>::spec_next(move _6) -> [return: bb2, unwind: bb8];
} }
bb2: { bb2: {

View file

@ -1,13 +1,13 @@
// MIR for `range_inclusive_iter_next` after PreCodegen // MIR for `range_inclusive_iter_next` after PreCodegen
fn range_inclusive_iter_next(_1: &mut RangeInclusive<u32>) -> Option<u32> { fn range_inclusive_iter_next(_1: &mut std::ops::RangeInclusive<u32>) -> Option<u32> {
debug it => _1; debug it => _1;
let mut _0: std::option::Option<u32>; let mut _0: std::option::Option<u32>;
scope 1 (inlined iter::range::<impl Iterator for RangeInclusive<u32>>::next) { scope 1 (inlined iter::range::<impl Iterator for std::ops::RangeInclusive<u32>>::next) {
} }
bb0: { bb0: {
_0 = <RangeInclusive<u32> as iter::range::RangeInclusiveIteratorImpl>::spec_next(move _1) -> [return: bb1, unwind unreachable]; _0 = <std::ops::RangeInclusive<u32> as iter::range::RangeInclusiveIteratorImpl>::spec_next(move _1) -> [return: bb1, unwind unreachable];
} }
bb1: { bb1: {

View file

@ -1,13 +1,13 @@
// MIR for `range_inclusive_iter_next` after PreCodegen // MIR for `range_inclusive_iter_next` after PreCodegen
fn range_inclusive_iter_next(_1: &mut RangeInclusive<u32>) -> Option<u32> { fn range_inclusive_iter_next(_1: &mut std::ops::RangeInclusive<u32>) -> Option<u32> {
debug it => _1; debug it => _1;
let mut _0: std::option::Option<u32>; let mut _0: std::option::Option<u32>;
scope 1 (inlined iter::range::<impl Iterator for RangeInclusive<u32>>::next) { scope 1 (inlined iter::range::<impl Iterator for std::ops::RangeInclusive<u32>>::next) {
} }
bb0: { bb0: {
_0 = <RangeInclusive<u32> as iter::range::RangeInclusiveIteratorImpl>::spec_next(move _1) -> [return: bb1, unwind continue]; _0 = <std::ops::RangeInclusive<u32> as iter::range::RangeInclusiveIteratorImpl>::spec_next(move _1) -> [return: bb1, unwind continue];
} }
bb1: { bb1: {

View file

@ -4,7 +4,7 @@ error[E0741]: `std::ops::Range<usize>` must implement `ConstParamTy` to be used
LL | struct _Range<const R: std::ops::Range<usize>>; LL | struct _Range<const R: std::ops::Range<usize>>;
| ^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^
error[E0741]: `RangeFrom<usize>` must implement `ConstParamTy` to be used as the type of a const generic parameter error[E0741]: `std::ops::RangeFrom<usize>` must implement `ConstParamTy` to be used as the type of a const generic parameter
--> $DIR/const-generics-range.rs:13:28 --> $DIR/const-generics-range.rs:13:28
| |
LL | struct _RangeFrom<const R: std::ops::RangeFrom<usize>>; 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
LL | struct _RangeFull<const R: std::ops::RangeFull>; LL | struct _RangeFull<const R: std::ops::RangeFull>;
| ^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^
error[E0741]: `RangeInclusive<usize>` must implement `ConstParamTy` to be used as the type of a const generic parameter error[E0741]: `std::ops::RangeInclusive<usize>` must implement `ConstParamTy` to be used as the type of a const generic parameter
--> $DIR/const-generics-range.rs:24:33 --> $DIR/const-generics-range.rs:24:33
| |
LL | struct _RangeInclusive<const R: std::ops::RangeInclusive<usize>>; LL | struct _RangeInclusive<const R: std::ops::RangeInclusive<usize>>;

View file

@ -10,7 +10,7 @@ help: add `#![feature(adt_const_params)]` to the crate attributes to enable more
LL + #![feature(adt_const_params)] LL + #![feature(adt_const_params)]
| |
error: `RangeFrom<usize>` is forbidden as the type of a const generic parameter error: `std::ops::RangeFrom<usize>` is forbidden as the type of a const generic parameter
--> $DIR/const-generics-range.rs:13:28 --> $DIR/const-generics-range.rs:13:28
| |
LL | struct _RangeFrom<const R: std::ops::RangeFrom<usize>>; 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
LL + #![feature(adt_const_params)] LL + #![feature(adt_const_params)]
| |
error: `RangeInclusive<usize>` is forbidden as the type of a const generic parameter error: `std::ops::RangeInclusive<usize>` is forbidden as the type of a const generic parameter
--> $DIR/const-generics-range.rs:24:33 --> $DIR/const-generics-range.rs:24:33
| |
LL | struct _RangeInclusive<const R: std::ops::RangeInclusive<usize>>; LL | struct _RangeInclusive<const R: std::ops::RangeInclusive<usize>>;

View file

@ -11,7 +11,7 @@ const RANGE : _Range<{ 0 .. 1000 }> = _Range;
// `RangeFrom` should be usable within const generics: // `RangeFrom` should be usable within const generics:
struct _RangeFrom<const R: std::ops::RangeFrom<usize>>; struct _RangeFrom<const R: std::ops::RangeFrom<usize>>;
//[min]~^ ERROR `RangeFrom<usize>` is forbidden //[min]~^ ERROR `std::ops::RangeFrom<usize>` is forbidden
const RANGE_FROM : _RangeFrom<{ 0 .. }> = _RangeFrom; const RANGE_FROM : _RangeFrom<{ 0 .. }> = _RangeFrom;
// `RangeFull` should be usable within const generics: // `RangeFull` should be usable within const generics:
@ -22,7 +22,7 @@ const RANGE_FULL : _RangeFull<{ .. }> = _RangeFull;
// Regression test for #70155 // Regression test for #70155
// `RangeInclusive` should be usable within const generics: // `RangeInclusive` should be usable within const generics:
struct _RangeInclusive<const R: std::ops::RangeInclusive<usize>>; struct _RangeInclusive<const R: std::ops::RangeInclusive<usize>>;
//[min]~^ ERROR `RangeInclusive<usize>` is forbidden //[min]~^ ERROR `std::ops::RangeInclusive<usize>` is forbidden
const RANGE_INCLUSIVE : _RangeInclusive<{ 0 ..= 999 }> = _RangeInclusive; const RANGE_INCLUSIVE : _RangeInclusive<{ 0 ..= 999 }> = _RangeInclusive;
// `RangeTo` should be usable within const generics: // `RangeTo` should be usable within const generics:

View file

@ -0,0 +1,10 @@
#![feature(new_range_api)]
fn main() {
let a: core::range::RangeFrom<u8> = 1..;
//~^ mismatched types
let b: core::range::Range<u8> = 2..3;
//~^ mismatched types
let c: core::range::RangeInclusive<u8> = 4..=5;
//~^ mismatched types
}

View file

@ -0,0 +1,48 @@
error[E0308]: mismatched types
--> $DIR/feature-gate-new_range.rs:4:41
|
LL | let a: core::range::RangeFrom<u8> = 1..;
| -------------------------- ^^^ expected `RangeFrom<u8>`, found `RangeFrom<{integer}>`
| |
| expected due to this
|
= note: expected struct `std::range::RangeFrom<u8>`
found struct `std::ops::RangeFrom<{integer}>`
help: call `Into::into` on this expression to convert `std::ops::RangeFrom<{integer}>` into `std::range::RangeFrom<u8>`
|
LL | let a: core::range::RangeFrom<u8> = 1...into();
| +++++++
error[E0308]: mismatched types
--> $DIR/feature-gate-new_range.rs:6:37
|
LL | let b: core::range::Range<u8> = 2..3;
| ---------------------- ^^^^ expected `Range<u8>`, found `Range<{integer}>`
| |
| expected due to this
|
= note: expected struct `std::range::Range<u8>`
found struct `std::ops::Range<{integer}>`
help: call `Into::into` on this expression to convert `std::ops::Range<{integer}>` into `std::range::Range<u8>`
|
LL | let b: core::range::Range<u8> = 2..3.into();
| +++++++
error[E0308]: mismatched types
--> $DIR/feature-gate-new_range.rs:8:46
|
LL | let c: core::range::RangeInclusive<u8> = 4..=5;
| ------------------------------- ^^^^^ expected `RangeInclusive<u8>`, found `RangeInclusive<{integer}>`
| |
| expected due to this
|
= note: expected struct `std::range::RangeInclusive<u8>`
found struct `std::ops::RangeInclusive<{integer}>`
help: call `Into::into` on this expression to convert `std::ops::RangeInclusive<{integer}>` into `std::range::RangeInclusive<u8>`
|
LL | let c: core::range::RangeInclusive<u8> = 4..=5.into();
| +++++++
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0308`.

View file

@ -21,7 +21,7 @@ LL | RANGE => {}
| `RANGE` is interpreted as a constant, not a new binding | `RANGE` is interpreted as a constant, not a new binding
| |
= note: expected type `i32` = note: expected type `i32`
found struct `RangeInclusive<i32>` found struct `std::ops::RangeInclusive<i32>`
help: you may want to move the range into the match block help: you may want to move the range into the match block
| |
LL | 0..=255 => {} LL | 0..=255 => {}
@ -43,7 +43,7 @@ LL | RANGE2 => {}
| `RANGE2` is interpreted as a constant, not a new binding | `RANGE2` is interpreted as a constant, not a new binding
| |
= note: expected type `i32` = note: expected type `i32`
found struct `RangeInclusive<i32>` found struct `std::ops::RangeInclusive<i32>`
= 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 = 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
error: aborting due to 3 previous errors error: aborting due to 3 previous errors

View file

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

View file

@ -1,14 +1,14 @@
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}` 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}`
--> $DIR/closure-arg-type-mismatch-issue-45727.rs:6:29 --> $DIR/closure-arg-type-mismatch-issue-45727.rs:6:29
| |
LL | let _ = (-10..=10).find(|x: i32| x.signum() == 0); LL | let _ = (-10..=10).find(|x: i32| x.signum() == 0);
| ---- ^^^^^^^^^^^^^^^^^^^^^^^^ expected an `FnMut(&<RangeInclusive<{integer}> as Iterator>::Item)` closure, found `{closure@$DIR/closure-arg-type-mismatch-issue-45727.rs:6:29: 6:37}` | ---- ^^^^^^^^^^^^^^^^^^^^^^^^ 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}`
| | | |
| required by a bound introduced by this call | required by a bound introduced by this call
| |
= 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}` = 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}`
= note: expected a closure with arguments `(i32,)` = note: expected a closure with arguments `(i32,)`
found a closure with arguments `(&<RangeInclusive<{integer}> as Iterator>::Item,)` found a closure with arguments `(&<std::ops::RangeInclusive<{integer}> as Iterator>::Item,)`
note: required by a bound in `find` note: required by a bound in `find`
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
@ -18,17 +18,17 @@ error[E0271]: expected `RangeInclusive<{integer}>` to be an iterator that yields
LL | let _ = (-10..=10).find(|x: &&&i32| x.signum() == 0); LL | let _ = (-10..=10).find(|x: &&&i32| x.signum() == 0);
| ^^^^ expected `&&i32`, found integer | ^^^^ expected `&&i32`, found integer
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}` 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}`
--> $DIR/closure-arg-type-mismatch-issue-45727.rs:9:29 --> $DIR/closure-arg-type-mismatch-issue-45727.rs:9:29
| |
LL | let _ = (-10..=10).find(|x: &&&i32| x.signum() == 0); LL | let _ = (-10..=10).find(|x: &&&i32| x.signum() == 0);
| ---- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected an `FnMut(&<RangeInclusive<{integer}> as Iterator>::Item)` closure, found `{closure@$DIR/closure-arg-type-mismatch-issue-45727.rs:9:29: 9:40}` | ---- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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}`
| | | |
| required by a bound introduced by this call | required by a bound introduced by this call
| |
= 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}` = 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}`
= note: expected a closure with arguments `(&&&i32,)` = note: expected a closure with arguments `(&&&i32,)`
found a closure with arguments `(&<RangeInclusive<{integer}> as Iterator>::Item,)` found a closure with arguments `(&<std::ops::RangeInclusive<{integer}> as Iterator>::Item,)`
note: required by a bound in `find` note: required by a bound in `find`
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL

View file

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

View file

@ -31,7 +31,7 @@ help: give the `break` a value of the expected type
LL | [(); loop { break 42 }]; LL | [(); loop { break 42 }];
| ++ | ++
error[E0015]: cannot use `for` loop on `RangeFrom<usize>` in constants error[E0015]: cannot use `for` loop on `std::ops::RangeFrom<usize>` in constants
--> $DIR/issue-52443.rs:9:21 --> $DIR/issue-52443.rs:9:21
| |
LL | [(); { for _ in 0usize.. {}; 0}]; LL | [(); { for _ in 0usize.. {}; 0}];
@ -39,7 +39,7 @@ LL | [(); { for _ in 0usize.. {}; 0}];
| |
= note: calls in constants are limited to constant functions, tuple structs and tuple variants = note: calls in constants are limited to constant functions, tuple structs and tuple variants
error[E0015]: cannot use `for` loop on `RangeFrom<usize>` in constants error[E0015]: cannot use `for` loop on `std::ops::RangeFrom<usize>` in constants
--> $DIR/issue-52443.rs:9:21 --> $DIR/issue-52443.rs:9:21
| |
LL | [(); { for _ in 0usize.. {}; 0}]; LL | [(); { for _ in 0usize.. {}; 0}];

View file

@ -0,0 +1,27 @@
//@ check-pass
#![feature(new_range_api)]
fn main() {
// Unchanged
let a: core::range::RangeFull = ..;
let b: core::range::RangeTo<u8> = ..2;
let c: core::range::RangeToInclusive<u8> = ..=3;
let _: core::ops::RangeFull = a;
let _: core::ops::RangeTo<u8> = b;
let _: core::ops::RangeToInclusive<u8> = c;
// Changed
let a: core::range::legacy::RangeFrom<u8> = 1..;
let b: core::range::legacy::Range<u8> = 2..3;
let c: core::range::legacy::RangeInclusive<u8> = 4..=5;
let a: core::ops::RangeFrom<u8> = a;
let b: core::ops::Range<u8> = b;
let c: core::ops::RangeInclusive<u8> = c;
let _: core::ops::RangeFrom<u8> = a.into_iter();
let _: core::ops::Range<u8> = b.into_iter();
let _: core::ops::RangeInclusive<u8> = c.into_iter();
}

View file

@ -0,0 +1,24 @@
//@ check-pass
#![feature(new_range_api)]
#![feature(new_range)]
fn main() {
// Unchanged
let a: core::range::RangeFull = ..;
let b: core::range::RangeTo<u8> = ..2;
let c: core::range::RangeToInclusive<u8> = ..=3;
let _: core::ops::RangeFull = a;
let _: core::ops::RangeTo<u8> = b;
let _: core::ops::RangeToInclusive<u8> = c;
// Changed
let a: core::range::RangeFrom<u8> = 1..;
let b: core::range::Range<u8> = 2..3;
let c: core::range::RangeInclusive<u8> = 4..=5;
let _: core::range::IterRangeFrom<u8> = a.into_iter();
let _: core::range::IterRange<u8> = b.into_iter();
let _: core::range::IterRangeInclusive<u8> = c.into_iter();
}

View file

@ -47,7 +47,7 @@ LL | take_range(std::ops::RangeFrom { start: 1 });
| arguments to this function are incorrect | arguments to this function are incorrect
| |
= note: expected reference `&_` = note: expected reference `&_`
found struct `RangeFrom<{integer}>` found struct `std::ops::RangeFrom<{integer}>`
note: function defined here note: function defined here
--> $DIR/issue-54505-no-literals.rs:12:4 --> $DIR/issue-54505-no-literals.rs:12:4
| |
@ -67,7 +67,7 @@ LL | take_range(::std::ops::RangeFrom { start: 1 });
| arguments to this function are incorrect | arguments to this function are incorrect
| |
= note: expected reference `&_` = note: expected reference `&_`
found struct `RangeFrom<{integer}>` found struct `std::ops::RangeFrom<{integer}>`
note: function defined here note: function defined here
--> $DIR/issue-54505-no-literals.rs:12:4 --> $DIR/issue-54505-no-literals.rs:12:4
| |
@ -127,7 +127,7 @@ LL | take_range(std::ops::RangeInclusive::new(0, 1));
| arguments to this function are incorrect | arguments to this function are incorrect
| |
= note: expected reference `&_` = note: expected reference `&_`
found struct `RangeInclusive<{integer}>` found struct `std::ops::RangeInclusive<{integer}>`
note: function defined here note: function defined here
--> $DIR/issue-54505-no-literals.rs:12:4 --> $DIR/issue-54505-no-literals.rs:12:4
| |
@ -147,7 +147,7 @@ LL | take_range(::std::ops::RangeInclusive::new(0, 1));
| arguments to this function are incorrect | arguments to this function are incorrect
| |
= note: expected reference `&_` = note: expected reference `&_`
found struct `RangeInclusive<{integer}>` found struct `std::ops::RangeInclusive<{integer}>`
note: function defined here note: function defined here
--> $DIR/issue-54505-no-literals.rs:12:4 --> $DIR/issue-54505-no-literals.rs:12:4
| |

View file

@ -27,7 +27,7 @@ LL | take_range(1..);
| arguments to this function are incorrect | arguments to this function are incorrect
| |
= note: expected reference `&_` = note: expected reference `&_`
found struct `RangeFrom<{integer}>` found struct `std::ops::RangeFrom<{integer}>`
note: function defined here note: function defined here
--> $DIR/issue-54505.rs:10:4 --> $DIR/issue-54505.rs:10:4
| |
@ -72,7 +72,7 @@ LL | take_range(0..=1);
| arguments to this function are incorrect | arguments to this function are incorrect
| |
= note: expected reference `&_` = note: expected reference `&_`
found struct `RangeInclusive<{integer}>` found struct `std::ops::RangeInclusive<{integer}>`
note: function defined here note: function defined here
--> $DIR/issue-54505.rs:10:4 --> $DIR/issue-54505.rs:10:4
| |

View file

@ -30,7 +30,7 @@ LL | let range = *arr..;
| ^^^^ doesn't have a size known at compile-time | ^^^^ doesn't have a size known at compile-time
| |
= help: the trait `Sized` is not implemented for `[{integer}]` = help: the trait `Sized` is not implemented for `[{integer}]`
note: required by an implicit `Sized` bound in `RangeFrom` note: required by an implicit `Sized` bound in `std::ops::RangeFrom`
--> $SRC_DIR/core/src/ops/range.rs:LL:COL --> $SRC_DIR/core/src/ops/range.rs:LL:COL
error: aborting due to 3 previous errors error: aborting due to 3 previous errors

View file

@ -22,7 +22,7 @@ LL | let _: f64 = 1..;
| expected due to this | expected due to this
| |
= note: expected type `f64` = note: expected type `f64`
found struct `RangeFrom<{integer}>` found struct `std::ops::RangeFrom<{integer}>`
help: remove the unnecessary `.` operator for a floating point literal help: remove the unnecessary `.` operator for a floating point literal
| |
LL | let _: f64 = 1.; LL | let _: f64 = 1.;