about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compiler/rustc_ast_lowering/src/expr.rs29
-rw-r--r--compiler/rustc_hir/src/hir.rs15
-rw-r--r--compiler/rustc_hir/src/lang_items.rs1
-rw-r--r--compiler/rustc_index/src/idx.rs15
-rw-r--r--compiler/rustc_span/src/symbol.rs2
-rw-r--r--library/core/src/range.rs140
-rw-r--r--library/core/src/range/iter.rs2
-rw-r--r--library/core/src/range/legacy.rs4
-rw-r--r--library/core/src/slice/index.rs41
-rw-r--r--library/core/src/str/traits.rs8
-rw-r--r--src/tools/clippy/clippy_utils/src/sym.rs1
-rw-r--r--tests/ui/const-generics/std/const-generics-range.full.stderr2
-rw-r--r--tests/ui/const-generics/std/const-generics-range.min.stderr2
-rw-r--r--tests/ui/const-generics/std/const-generics-range.rs14
-rw-r--r--tests/ui/iterators/ranges.stderr6
-rw-r--r--tests/ui/new-range/disabled.rs4
-rw-r--r--tests/ui/new-range/enabled.rs4
-rw-r--r--tests/ui/range/issue-54505-no-literals.stderr4
-rw-r--r--tests/ui/range/issue-54505-no-std.stderr2
-rw-r--r--tests/ui/range/issue-54505.stderr2
20 files changed, 245 insertions, 53 deletions
diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs
index 3674814b796..bb6b25baf01 100644
--- a/compiler/rustc_ast_lowering/src/expr.rs
+++ b/compiler/rustc_ast_lowering/src/expr.rs
@@ -1536,7 +1536,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
                     hir::LangItem::Range
                 }
             }
-            (None, Some(..), Closed) => hir::LangItem::RangeToInclusive,
+            (None, Some(..), Closed) => {
+                if self.tcx.features().new_range() {
+                    hir::LangItem::RangeToInclusiveCopy
+                } else {
+                    hir::LangItem::RangeToInclusive
+                }
+            }
             (Some(e1), Some(e2), Closed) => {
                 if self.tcx.features().new_range() {
                     hir::LangItem::RangeInclusiveCopy
@@ -1560,13 +1566,26 @@ impl<'hir> LoweringContext<'_, 'hir> {
         };
 
         let fields = self.arena.alloc_from_iter(
-            e1.iter().map(|e| (sym::start, e)).chain(e2.iter().map(|e| (sym::end, e))).map(
-                |(s, e)| {
+            e1.iter()
+                .map(|e| (sym::start, e))
+                .chain(e2.iter().map(|e| {
+                    (
+                        if matches!(
+                            lang_item,
+                            hir::LangItem::RangeInclusiveCopy | hir::LangItem::RangeToInclusiveCopy
+                        ) {
+                            sym::last
+                        } else {
+                            sym::end
+                        },
+                        e,
+                    )
+                }))
+                .map(|(s, e)| {
                     let expr = self.lower_expr(e);
                     let ident = Ident::new(s, self.lower_span(e.span));
                     self.expr_field(ident, expr, e.span)
-                },
-            ),
+                }),
         );
 
         hir::ExprKind::Struct(
diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs
index ae03121e5f7..75551fe4c19 100644
--- a/compiler/rustc_hir/src/hir.rs
+++ b/compiler/rustc_hir/src/hir.rs
@@ -2616,6 +2616,18 @@ impl Expr<'_> {
             )
             | (
                 ExprKind::Struct(
+                    QPath::LangItem(LangItem::RangeToInclusiveCopy, _),
+                    [val1],
+                    StructTailExpr::None,
+                ),
+                ExprKind::Struct(
+                    QPath::LangItem(LangItem::RangeToInclusiveCopy, _),
+                    [val2],
+                    StructTailExpr::None,
+                ),
+            )
+            | (
+                ExprKind::Struct(
                     QPath::LangItem(LangItem::RangeFrom, _),
                     [val1],
                     StructTailExpr::None,
@@ -2705,7 +2717,8 @@ pub fn is_range_literal(expr: &Expr<'_>) -> bool {
                     | LangItem::RangeToInclusive
                     | LangItem::RangeCopy
                     | LangItem::RangeFromCopy
-                    | LangItem::RangeInclusiveCopy,
+                    | LangItem::RangeInclusiveCopy
+                    | LangItem::RangeToInclusiveCopy,
                 ..
             )
         ),
diff --git a/compiler/rustc_hir/src/lang_items.rs b/compiler/rustc_hir/src/lang_items.rs
index 0464665b41f..67d2f15d414 100644
--- a/compiler/rustc_hir/src/lang_items.rs
+++ b/compiler/rustc_hir/src/lang_items.rs
@@ -422,6 +422,7 @@ language_item_table! {
     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;
+    RangeToInclusiveCopy,    sym::RangeToInclusiveCopy,     range_to_inclusive_copy_struct, Target::Struct, GenericRequirement::None;
 
     String,                  sym::String,              string,                     Target::Struct,         GenericRequirement::None;
     CStr,                    sym::CStr,                c_str,                      Target::Struct,         GenericRequirement::None;
diff --git a/compiler/rustc_index/src/idx.rs b/compiler/rustc_index/src/idx.rs
index 33f406e2113..9cd7134659c 100644
--- a/compiler/rustc_index/src/idx.rs
+++ b/compiler/rustc_index/src/idx.rs
@@ -130,7 +130,22 @@ impl<I: Idx, T> IntoSliceIdx<I, [T]> for core::range::RangeFrom<I> {
 impl<I: Idx, T> IntoSliceIdx<I, [T]> for core::range::RangeInclusive<I> {
     type Output = core::range::RangeInclusive<usize>;
     #[inline]
+    #[cfg(bootstrap)]
     fn into_slice_idx(self) -> Self::Output {
         core::range::RangeInclusive { start: self.start.index(), end: self.end.index() }
     }
+    #[inline]
+    #[cfg(not(bootstrap))]
+    fn into_slice_idx(self) -> Self::Output {
+        core::range::RangeInclusive { start: self.start.index(), last: self.last.index() }
+    }
+}
+
+#[cfg(all(feature = "nightly", not(bootstrap)))]
+impl<I: Idx, T> IntoSliceIdx<I, [T]> for core::range::RangeToInclusive<I> {
+    type Output = core::range::RangeToInclusive<usize>;
+    #[inline]
+    fn into_slice_idx(self) -> Self::Output {
+        core::range::RangeToInclusive { last: self.last.index() }
+    }
 }
diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs
index e5108d8b7e9..ffdc640c285 100644
--- a/compiler/rustc_span/src/symbol.rs
+++ b/compiler/rustc_span/src/symbol.rs
@@ -326,6 +326,7 @@ symbols! {
         RangeSub,
         RangeTo,
         RangeToInclusive,
+        RangeToInclusiveCopy,
         Rc,
         RcWeak,
         Ready,
@@ -1280,6 +1281,7 @@ symbols! {
         lang,
         lang_items,
         large_assignments,
+        last,
         lateout,
         lazy_normalization_consts,
         lazy_type_alias,
diff --git a/library/core/src/range.rs b/library/core/src/range.rs
index 332ae51d848..8c49123fdaf 100644
--- a/library/core/src/range.rs
+++ b/library/core/src/range.rs
@@ -31,9 +31,7 @@ pub use iter::{IterRange, IterRangeFrom, IterRangeInclusive};
 #[doc(inline)]
 pub use crate::iter::Step;
 #[doc(inline)]
-pub use crate::ops::{
-    Bound, IntoBounds, OneSidedRange, RangeBounds, RangeFull, RangeTo, RangeToInclusive,
-};
+pub use crate::ops::{Bound, IntoBounds, OneSidedRange, RangeBounds, RangeFull, RangeTo};
 
 /// A (half-open) range bounded inclusively below and exclusively above
 /// (`start..end` in a future edition).
@@ -209,20 +207,20 @@ impl<T> const From<legacy::Range<T>> for Range<T> {
     }
 }
 
-/// A range bounded inclusively below and above (`start..=end`).
+/// A range bounded inclusively below and above (`start..=last`).
 ///
-/// The `RangeInclusive` `start..=end` contains all values with `x >= start`
-/// and `x <= end`. It is empty unless `start <= end`.
+/// The `RangeInclusive` `start..=last` contains all values with `x >= start`
+/// and `x <= last`. It is empty unless `start <= last`.
 ///
 /// # Examples
 ///
-/// The `start..=end` syntax is a `RangeInclusive`:
+/// The `start..=last` syntax is a `RangeInclusive`:
 ///
 /// ```
 /// #![feature(new_range_api)]
 /// use core::range::RangeInclusive;
 ///
-/// assert_eq!(RangeInclusive::from(3..=5), RangeInclusive { start: 3, end: 5 });
+/// assert_eq!(RangeInclusive::from(3..=5), RangeInclusive { start: 3, last: 5 });
 /// assert_eq!(3 + 4 + 5, RangeInclusive::from(3..=5).into_iter().sum());
 /// ```
 #[lang = "RangeInclusiveCopy"]
@@ -234,7 +232,7 @@ pub struct RangeInclusive<Idx> {
     pub start: Idx,
     /// The upper bound of the range (inclusive).
     #[unstable(feature = "new_range_api", issue = "125687")]
-    pub end: Idx,
+    pub last: Idx,
 }
 
 #[unstable(feature = "new_range_api", issue = "125687")]
@@ -242,7 +240,7 @@ impl<Idx: fmt::Debug> fmt::Debug for RangeInclusive<Idx> {
     fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
         self.start.fmt(fmt)?;
         write!(fmt, "..=")?;
-        self.end.fmt(fmt)?;
+        self.last.fmt(fmt)?;
         Ok(())
     }
 }
@@ -306,7 +304,7 @@ impl<Idx: PartialOrd<Idx>> RangeInclusive<Idx> {
     #[unstable(feature = "new_range_api", issue = "125687")]
     #[inline]
     pub fn is_empty(&self) -> bool {
-        !(self.start <= self.end)
+        !(self.start <= self.last)
     }
 }
 
@@ -335,10 +333,10 @@ impl<Idx: Step> RangeInclusive<Idx> {
 
 impl RangeInclusive<usize> {
     /// Converts to an exclusive `Range` for `SliceIndex` implementations.
-    /// The caller is responsible for dealing with `end == usize::MAX`.
+    /// The caller is responsible for dealing with `last == usize::MAX`.
     #[inline]
     pub(crate) const fn into_slice_range(self) -> Range<usize> {
-        Range { start: self.start, end: self.end + 1 }
+        Range { start: self.start, end: self.last + 1 }
     }
 }
 
@@ -348,7 +346,7 @@ impl<T> RangeBounds<T> for RangeInclusive<T> {
         Included(&self.start)
     }
     fn end_bound(&self) -> Bound<&T> {
-        Included(&self.end)
+        Included(&self.last)
     }
 }
 
@@ -364,7 +362,7 @@ impl<T> RangeBounds<T> for RangeInclusive<&T> {
         Included(self.start)
     }
     fn end_bound(&self) -> Bound<&T> {
-        Included(self.end)
+        Included(self.last)
     }
 }
 
@@ -372,7 +370,7 @@ impl<T> RangeBounds<T> for RangeInclusive<&T> {
 #[unstable(feature = "new_range_api", issue = "125687")]
 impl<T> IntoBounds<T> for RangeInclusive<T> {
     fn into_bounds(self) -> (Bound<T>, Bound<T>) {
-        (Included(self.start), Included(self.end))
+        (Included(self.start), Included(self.last))
     }
 }
 
@@ -381,7 +379,7 @@ impl<T> IntoBounds<T> for RangeInclusive<T> {
 impl<T> const From<RangeInclusive<T>> for legacy::RangeInclusive<T> {
     #[inline]
     fn from(value: RangeInclusive<T>) -> Self {
-        Self::new(value.start, value.end)
+        Self::new(value.start, value.last)
     }
 }
 #[unstable(feature = "new_range_api", issue = "125687")]
@@ -394,8 +392,8 @@ impl<T> const From<legacy::RangeInclusive<T>> for RangeInclusive<T> {
             "attempted to convert from an exhausted `legacy::RangeInclusive` (unspecified behavior)"
         );
 
-        let (start, end) = value.into_inner();
-        RangeInclusive { start, end }
+        let (start, last) = value.into_inner();
+        RangeInclusive { start, last }
     }
 }
 
@@ -544,3 +542,107 @@ impl<T> const From<legacy::RangeFrom<T>> for RangeFrom<T> {
         Self { start: value.start }
     }
 }
+
+/// A range only bounded inclusively above (`..=last`).
+///
+/// The `RangeToInclusive` `..=last` contains all values with `x <= last`.
+/// It cannot serve as an [`Iterator`] because it doesn't have a starting point.
+///
+/// # Examples
+///
+/// The `..=last` syntax is a `RangeToInclusive`:
+///
+/// ```
+/// #![feature(new_range_api)]
+/// #![feature(new_range)]
+/// assert_eq!((..=5), std::range::RangeToInclusive{ last: 5 });
+/// ```
+///
+/// It does not have an [`IntoIterator`] implementation, so you can't use it in a
+/// `for` loop directly. This won't compile:
+///
+/// ```compile_fail,E0277
+/// // error[E0277]: the trait bound `std::range::RangeToInclusive<{integer}>:
+/// // std::iter::Iterator` is not satisfied
+/// for i in ..=5 {
+///     // ...
+/// }
+/// ```
+///
+/// When used as a [slicing index], `RangeToInclusive` produces a slice of all
+/// array elements up to and including the index indicated by `last`.
+///
+/// ```
+/// let arr = [0, 1, 2, 3, 4];
+/// assert_eq!(arr[ ..  ], [0, 1, 2, 3, 4]);
+/// assert_eq!(arr[ .. 3], [0, 1, 2      ]);
+/// assert_eq!(arr[ ..=3], [0, 1, 2, 3   ]); // This is a `RangeToInclusive`
+/// assert_eq!(arr[1..  ], [   1, 2, 3, 4]);
+/// assert_eq!(arr[1.. 3], [   1, 2      ]);
+/// assert_eq!(arr[1..=3], [   1, 2, 3   ]);
+/// ```
+///
+/// [slicing index]: crate::slice::SliceIndex
+#[lang = "RangeToInclusiveCopy"]
+#[doc(alias = "..=")]
+#[derive(Copy, Clone, PartialEq, Eq, Hash)]
+#[unstable(feature = "new_range_api", issue = "125687")]
+pub struct RangeToInclusive<Idx> {
+    /// The upper bound of the range (inclusive)
+    #[unstable(feature = "new_range_api", issue = "125687")]
+    pub last: Idx,
+}
+
+#[unstable(feature = "new_range_api", issue = "125687")]
+impl<Idx: fmt::Debug> fmt::Debug for RangeToInclusive<Idx> {
+    fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
+        write!(fmt, "..=")?;
+        self.last.fmt(fmt)?;
+        Ok(())
+    }
+}
+
+impl<Idx: PartialOrd<Idx>> RangeToInclusive<Idx> {
+    /// Returns `true` if `item` is contained in the range.
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// assert!( (..=5).contains(&-1_000_000_000));
+    /// assert!( (..=5).contains(&5));
+    /// assert!(!(..=5).contains(&6));
+    ///
+    /// assert!( (..=1.0).contains(&1.0));
+    /// assert!(!(..=1.0).contains(&f32::NAN));
+    /// assert!(!(..=f32::NAN).contains(&0.5));
+    /// ```
+    #[inline]
+    #[unstable(feature = "new_range_api", issue = "125687")]
+    pub fn contains<U>(&self, item: &U) -> bool
+    where
+        Idx: PartialOrd<U>,
+        U: ?Sized + PartialOrd<Idx>,
+    {
+        <Self as RangeBounds<Idx>>::contains(self, item)
+    }
+}
+
+// RangeToInclusive<Idx> cannot impl From<RangeTo<Idx>>
+// because underflow would be possible with (..0).into()
+
+#[unstable(feature = "new_range_api", issue = "125687")]
+impl<T> RangeBounds<T> for RangeToInclusive<T> {
+    fn start_bound(&self) -> Bound<&T> {
+        Unbounded
+    }
+    fn end_bound(&self) -> Bound<&T> {
+        Included(&self.last)
+    }
+}
+
+#[unstable(feature = "range_into_bounds", issue = "136903")]
+impl<T> IntoBounds<T> for RangeToInclusive<T> {
+    fn into_bounds(self) -> (Bound<T>, Bound<T>) {
+        (Unbounded, Included(self.last))
+    }
+}
diff --git a/library/core/src/range/iter.rs b/library/core/src/range/iter.rs
index 1e261d8c1d9..24efd4a204a 100644
--- a/library/core/src/range/iter.rs
+++ b/library/core/src/range/iter.rs
@@ -164,7 +164,7 @@ impl<A: Step> IterRangeInclusive<A> {
             return None;
         }
 
-        Some(RangeInclusive { start: self.0.start, end: self.0.end })
+        Some(RangeInclusive { start: self.0.start, last: self.0.end })
     }
 }
 
diff --git a/library/core/src/range/legacy.rs b/library/core/src/range/legacy.rs
index 6723c4903f7..aa11331382d 100644
--- a/library/core/src/range/legacy.rs
+++ b/library/core/src/range/legacy.rs
@@ -1,10 +1,10 @@
 //! # Legacy range types
 //!
 //! The types within this module will be replaced by the types
-//! [`Range`], [`RangeInclusive`], and [`RangeFrom`] in the parent
+//! [`Range`], [`RangeInclusive`], [`RangeToInclusive`], and [`RangeFrom`] in the parent
 //! module, [`core::range`].
 //!
 //! The types here are equivalent to those in [`core::ops`].
 
 #[doc(inline)]
-pub use crate::ops::{Range, RangeFrom, RangeInclusive};
+pub use crate::ops::{Range, RangeFrom, RangeInclusive, RangeToInclusive};
diff --git a/library/core/src/slice/index.rs b/library/core/src/slice/index.rs
index 8e1bc0bae70..a8147d745f3 100644
--- a/library/core/src/slice/index.rs
+++ b/library/core/src/slice/index.rs
@@ -129,6 +129,8 @@ mod private_slice_index {
     #[unstable(feature = "new_range_api", issue = "125687")]
     impl Sealed for range::RangeInclusive<usize> {}
     #[unstable(feature = "new_range_api", issue = "125687")]
+    impl Sealed for range::RangeToInclusive<usize> {}
+    #[unstable(feature = "new_range_api", issue = "125687")]
     impl Sealed for range::RangeFrom<usize> {}
 
     impl Sealed for ops::IndexRange {}
@@ -788,6 +790,45 @@ unsafe impl<T> const SliceIndex<[T]> for ops::RangeToInclusive<usize> {
     }
 }
 
+/// The methods `index` and `index_mut` panic if the end of the range is out of bounds.
+#[stable(feature = "inclusive_range", since = "1.26.0")]
+#[rustc_const_unstable(feature = "const_index", issue = "143775")]
+unsafe impl<T> const SliceIndex<[T]> for range::RangeToInclusive<usize> {
+    type Output = [T];
+
+    #[inline]
+    fn get(self, slice: &[T]) -> Option<&[T]> {
+        (0..=self.last).get(slice)
+    }
+
+    #[inline]
+    fn get_mut(self, slice: &mut [T]) -> Option<&mut [T]> {
+        (0..=self.last).get_mut(slice)
+    }
+
+    #[inline]
+    unsafe fn get_unchecked(self, slice: *const [T]) -> *const [T] {
+        // SAFETY: the caller has to uphold the safety contract for `get_unchecked`.
+        unsafe { (0..=self.last).get_unchecked(slice) }
+    }
+
+    #[inline]
+    unsafe fn get_unchecked_mut(self, slice: *mut [T]) -> *mut [T] {
+        // SAFETY: the caller has to uphold the safety contract for `get_unchecked_mut`.
+        unsafe { (0..=self.last).get_unchecked_mut(slice) }
+    }
+
+    #[inline]
+    fn index(self, slice: &[T]) -> &[T] {
+        (0..=self.last).index(slice)
+    }
+
+    #[inline]
+    fn index_mut(self, slice: &mut [T]) -> &mut [T] {
+        (0..=self.last).index_mut(slice)
+    }
+}
+
 /// Performs bounds checking of a range.
 ///
 /// This method is similar to [`Index::index`] for slices, but it returns a
diff --git a/library/core/src/str/traits.rs b/library/core/src/str/traits.rs
index 4f228edf78e..5adae62b7e6 100644
--- a/library/core/src/str/traits.rs
+++ b/library/core/src/str/traits.rs
@@ -677,11 +677,11 @@ unsafe impl const SliceIndex<str> for range::RangeInclusive<usize> {
     type Output = str;
     #[inline]
     fn get(self, slice: &str) -> Option<&Self::Output> {
-        if self.end == usize::MAX { None } else { self.into_slice_range().get(slice) }
+        if self.last == usize::MAX { None } else { self.into_slice_range().get(slice) }
     }
     #[inline]
     fn get_mut(self, slice: &mut str) -> Option<&mut Self::Output> {
-        if self.end == usize::MAX { None } else { self.into_slice_range().get_mut(slice) }
+        if self.last == usize::MAX { None } else { self.into_slice_range().get_mut(slice) }
     }
     #[inline]
     unsafe fn get_unchecked(self, slice: *const str) -> *const Self::Output {
@@ -695,14 +695,14 @@ unsafe impl const SliceIndex<str> for range::RangeInclusive<usize> {
     }
     #[inline]
     fn index(self, slice: &str) -> &Self::Output {
-        if self.end == usize::MAX {
+        if self.last == usize::MAX {
             str_index_overflow_fail();
         }
         self.into_slice_range().index(slice)
     }
     #[inline]
     fn index_mut(self, slice: &mut str) -> &mut Self::Output {
-        if self.end == usize::MAX {
+        if self.last == usize::MAX {
             str_index_overflow_fail();
         }
         self.into_slice_range().index_mut(slice)
diff --git a/src/tools/clippy/clippy_utils/src/sym.rs b/src/tools/clippy/clippy_utils/src/sym.rs
index 278101ac27f..8033b74a8d2 100644
--- a/src/tools/clippy/clippy_utils/src/sym.rs
+++ b/src/tools/clippy/clippy_utils/src/sym.rs
@@ -194,7 +194,6 @@ generate! {
     itertools,
     join,
     kw,
-    last,
     lazy_static,
     lint_vec,
     ln,
diff --git a/tests/ui/const-generics/std/const-generics-range.full.stderr b/tests/ui/const-generics/std/const-generics-range.full.stderr
index 2b5c63e6643..ccede2af9e5 100644
--- a/tests/ui/const-generics/std/const-generics-range.full.stderr
+++ b/tests/ui/const-generics/std/const-generics-range.full.stderr
@@ -28,7 +28,7 @@ error[E0741]: `RangeTo<usize>` must implement `ConstParamTy` to be used as the t
 LL | struct _RangeTo<const R: std::ops::RangeTo<usize>>;
    |                          ^^^^^^^^^^^^^^^^^^^^^^^^
 
-error[E0741]: `RangeToInclusive<usize>` must implement `ConstParamTy` to be used as the type of a const generic parameter
+error[E0741]: `std::ops::RangeToInclusive<usize>` must implement `ConstParamTy` to be used as the type of a const generic parameter
   --> $DIR/const-generics-range.rs:34:35
    |
 LL | struct _RangeToInclusive<const R: std::ops::RangeToInclusive<usize>>;
diff --git a/tests/ui/const-generics/std/const-generics-range.min.stderr b/tests/ui/const-generics/std/const-generics-range.min.stderr
index 04e3fe74453..43a57c880d5 100644
--- a/tests/ui/const-generics/std/const-generics-range.min.stderr
+++ b/tests/ui/const-generics/std/const-generics-range.min.stderr
@@ -58,7 +58,7 @@ help: add `#![feature(adt_const_params)]` to the crate attributes to enable more
 LL + #![feature(adt_const_params)]
    |
 
-error: `RangeToInclusive<usize>` is forbidden as the type of a const generic parameter
+error: `std::ops::RangeToInclusive<usize>` is forbidden as the type of a const generic parameter
   --> $DIR/const-generics-range.rs:34:35
    |
 LL | struct _RangeToInclusive<const R: std::ops::RangeToInclusive<usize>>;
diff --git a/tests/ui/const-generics/std/const-generics-range.rs b/tests/ui/const-generics/std/const-generics-range.rs
index 3a238ed177e..391366dadba 100644
--- a/tests/ui/const-generics/std/const-generics-range.rs
+++ b/tests/ui/const-generics/std/const-generics-range.rs
@@ -7,32 +7,32 @@
 // `Range` should be usable within const generics:
 struct _Range<const R: std::ops::Range<usize>>;
 //[min]~^ ERROR `std::ops::Range<usize>` is forbidden
-const RANGE : _Range<{ 0 .. 1000 }> = _Range;
+const RANGE: _Range<{ 0..1000 }> = _Range;
 
 // `RangeFrom` should be usable within const generics:
 struct _RangeFrom<const R: std::ops::RangeFrom<usize>>;
 //[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:
 struct _RangeFull<const R: std::ops::RangeFull>;
 //[min]~^ ERROR `RangeFull` is forbidden
-const RANGE_FULL : _RangeFull<{ .. }> = _RangeFull;
+const RANGE_FULL: _RangeFull<{ .. }> = _RangeFull;
 
 // Regression test for #70155
 // `RangeInclusive` should be usable within const generics:
 struct _RangeInclusive<const R: std::ops::RangeInclusive<usize>>;
 //[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:
 struct _RangeTo<const R: std::ops::RangeTo<usize>>;
 //[min]~^ ERROR `RangeTo<usize>` is forbidden
-const RANGE_TO : _RangeTo<{ .. 1000 }> = _RangeTo;
+const RANGE_TO: _RangeTo<{ ..1000 }> = _RangeTo;
 
 // `RangeToInclusive` should be usable within const generics:
 struct _RangeToInclusive<const R: std::ops::RangeToInclusive<usize>>;
-//[min]~^ ERROR `RangeToInclusive<usize>` is forbidden
-const RANGE_TO_INCLUSIVE : _RangeToInclusive<{ ..= 999 }> = _RangeToInclusive;
+//[min]~^ ERROR `std::ops::RangeToInclusive<usize>` is forbidden
+const RANGE_TO_INCLUSIVE: _RangeToInclusive<{ ..=999 }> = _RangeToInclusive;
 
 pub fn main() {}
diff --git a/tests/ui/iterators/ranges.stderr b/tests/ui/iterators/ranges.stderr
index b9fbcd5304b..f85ce644073 100644
--- a/tests/ui/iterators/ranges.stderr
+++ b/tests/ui/iterators/ranges.stderr
@@ -8,15 +8,15 @@ LL |     for _ in ..10 {}
    = note: `..end` is a `RangeTo`, which cannot be iterated on; you might have meant to have a bounded `Range`: `0..end`
    = note: required for `RangeTo<{integer}>` to implement `IntoIterator`
 
-error[E0277]: `RangeToInclusive<{integer}>` is not an iterator
+error[E0277]: `std::ops::RangeToInclusive<{integer}>` is not an iterator
   --> $DIR/ranges.rs:4:14
    |
 LL |     for _ in ..=10 {}
    |              ^^^^^ if you meant to iterate until a value (including it), add a starting value
    |
-   = help: the trait `Iterator` is not implemented for `RangeToInclusive<{integer}>`
+   = help: the trait `Iterator` is not implemented for `std::ops::RangeToInclusive<{integer}>`
    = note: `..=end` is a `RangeToInclusive`, which cannot be iterated on; you might have meant to have a bounded `RangeInclusive`: `0..=end`
-   = note: required for `RangeToInclusive<{integer}>` to implement `IntoIterator`
+   = note: required for `std::ops::RangeToInclusive<{integer}>` to implement `IntoIterator`
 
 error: aborting due to 2 previous errors
 
diff --git a/tests/ui/new-range/disabled.rs b/tests/ui/new-range/disabled.rs
index 1a5fe3f9743..6ba29f5ca9a 100644
--- a/tests/ui/new-range/disabled.rs
+++ b/tests/ui/new-range/disabled.rs
@@ -6,20 +6,20 @@ 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 d: core::range::legacy::RangeToInclusive<u8> = ..=3;
 
     let a: core::ops::RangeFrom<u8> = a;
     let b: core::ops::Range<u8> = b;
     let c: core::ops::RangeInclusive<u8> = c;
+    let d: core::ops::RangeToInclusive<u8> = d;
 
     let _: core::ops::RangeFrom<u8> = a.into_iter();
     let _: core::ops::Range<u8> = b.into_iter();
diff --git a/tests/ui/new-range/enabled.rs b/tests/ui/new-range/enabled.rs
index a5fb76ad52b..5ddbba492e7 100644
--- a/tests/ui/new-range/enabled.rs
+++ b/tests/ui/new-range/enabled.rs
@@ -7,18 +7,18 @@ 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 d: core::range::RangeToInclusive<u8> = ..=3;
 
     let _: core::range::IterRangeFrom<u8> = a.into_iter();
     let _: core::range::IterRange<u8> = b.into_iter();
     let _: core::range::IterRangeInclusive<u8> = c.into_iter();
+    // RangeToInclusive has no Iterator implementation
 }
diff --git a/tests/ui/range/issue-54505-no-literals.stderr b/tests/ui/range/issue-54505-no-literals.stderr
index c6d4384bcd3..62e2fe4a838 100644
--- a/tests/ui/range/issue-54505-no-literals.stderr
+++ b/tests/ui/range/issue-54505-no-literals.stderr
@@ -207,7 +207,7 @@ LL |     take_range(std::ops::RangeToInclusive { end: 5 });
    |     arguments to this function are incorrect
    |
    = note: expected reference `&_`
-                 found struct `RangeToInclusive<{integer}>`
+                 found struct `std::ops::RangeToInclusive<{integer}>`
 note: function defined here
   --> $DIR/issue-54505-no-literals.rs:12:4
    |
@@ -227,7 +227,7 @@ LL |     take_range(::std::ops::RangeToInclusive { end: 5 });
    |     arguments to this function are incorrect
    |
    = note: expected reference `&_`
-                 found struct `RangeToInclusive<{integer}>`
+                 found struct `std::ops::RangeToInclusive<{integer}>`
 note: function defined here
   --> $DIR/issue-54505-no-literals.rs:12:4
    |
diff --git a/tests/ui/range/issue-54505-no-std.stderr b/tests/ui/range/issue-54505-no-std.stderr
index 2aa1d584046..866a82afb7e 100644
--- a/tests/ui/range/issue-54505-no-std.stderr
+++ b/tests/ui/range/issue-54505-no-std.stderr
@@ -112,7 +112,7 @@ LL |     take_range(..=42);
    |     arguments to this function are incorrect
    |
    = note: expected reference `&_`
-                 found struct `RangeToInclusive<{integer}>`
+                 found struct `core::ops::RangeToInclusive<{integer}>`
 note: function defined here
   --> $DIR/issue-54505-no-std.rs:25:4
    |
diff --git a/tests/ui/range/issue-54505.stderr b/tests/ui/range/issue-54505.stderr
index 8b669b2910f..4d94c6c2d09 100644
--- a/tests/ui/range/issue-54505.stderr
+++ b/tests/ui/range/issue-54505.stderr
@@ -112,7 +112,7 @@ LL |     take_range(..=42);
    |     arguments to this function are incorrect
    |
    = note: expected reference `&_`
-                 found struct `RangeToInclusive<{integer}>`
+                 found struct `std::ops::RangeToInclusive<{integer}>`
 note: function defined here
   --> $DIR/issue-54505.rs:10:4
    |