Rollup merge of #94657 - fee1-dead:const_slice_index, r=oli-obk

Constify `Index{,Mut}` for `[T]`, `str`, and `[T; N]`

Several panic functions were rewired (via `const_eval_select`) to simpler implementations that do not require formatting for compile-time usage.

r? ```@oli-obk```
This commit is contained in:
Matthias Krüger 2022-03-10 12:20:52 +01:00 committed by GitHub
commit fe034cb43b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 160 additions and 66 deletions

View File

@ -276,9 +276,10 @@ fn into_iter(self) -> IterMut<'a, T> {
}
#[stable(feature = "index_trait_on_arrays", since = "1.50.0")]
impl<T, I, const N: usize> Index<I> for [T; N]
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
impl<T, I, const N: usize> const Index<I> for [T; N]
where
[T]: Index<I>,
[T]: ~const Index<I>,
{
type Output = <[T] as Index<I>>::Output;
@ -289,9 +290,10 @@ fn index(&self, index: I) -> &Self::Output {
}
#[stable(feature = "index_trait_on_arrays", since = "1.50.0")]
impl<T, I, const N: usize> IndexMut<I> for [T; N]
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
impl<T, I, const N: usize> const IndexMut<I> for [T; N]
where
[T]: IndexMut<I>,
[T]: ~const IndexMut<I>,
{
#[inline]
fn index_mut(&mut self, index: I) -> &mut Self::Output {

View File

@ -149,6 +149,8 @@
#![feature(variant_count)]
#![feature(const_array_from_ref)]
#![feature(const_slice_from_ref)]
#![feature(const_slice_index)]
#![feature(const_is_char_boundary)]
//
// Language features:
#![feature(abi_unadjusted)]

View File

@ -809,7 +809,7 @@ pub fn escape_ascii(self) -> ascii::EscapeDefault {
ascii::escape_default(self)
}
pub(crate) fn is_utf8_char_boundary(self) -> bool {
pub(crate) const fn is_utf8_char_boundary(self) -> bool {
// This is bit magic equivalent to: b < 128 || b >= 192
(self as i8) >= -0x40
}

View File

@ -446,7 +446,7 @@ impl RangeInclusive<usize> {
/// Converts to an exclusive `Range` for `SliceIndex` implementations.
/// The caller is responsible for dealing with `end == usize::MAX`.
#[inline]
pub(crate) fn into_slice_range(self) -> Range<usize> {
pub(crate) const fn into_slice_range(self) -> Range<usize> {
// If we're not exhausted, we want to simply slice `start..end + 1`.
// If we are exhausted, then slicing with `end + 1..end + 1` gives us an
// empty range that is still subject to bounds-checks for that endpoint.

View File

@ -1032,10 +1032,11 @@ pub const fn as_ptr(self) -> *const T {
/// }
/// ```
#[unstable(feature = "slice_ptr_get", issue = "74265")]
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
#[inline]
pub unsafe fn get_unchecked<I>(self, index: I) -> *const I::Output
pub const unsafe fn get_unchecked<I>(self, index: I) -> *const I::Output
where
I: SliceIndex<[T]>,
I: ~const SliceIndex<[T]>,
{
// SAFETY: the caller ensures that `self` is dereferenceable and `index` in-bounds.
unsafe { index.get_unchecked(self) }

View File

@ -1302,10 +1302,11 @@ pub const fn as_mut_ptr(self) -> *mut T {
/// }
/// ```
#[unstable(feature = "slice_ptr_get", issue = "74265")]
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
#[inline(always)]
pub unsafe fn get_unchecked_mut<I>(self, index: I) -> *mut I::Output
pub const unsafe fn get_unchecked_mut<I>(self, index: I) -> *mut I::Output
where
I: SliceIndex<[T]>,
I: ~const SliceIndex<[T]>,
{
// SAFETY: the caller ensures that `self` is dereferenceable and `index` in-bounds.
unsafe { index.get_unchecked_mut(self) }

View File

@ -630,10 +630,11 @@ pub const fn as_mut_ptr(self) -> *mut T {
/// }
/// ```
#[unstable(feature = "slice_ptr_get", issue = "74265")]
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
#[inline]
pub unsafe fn get_unchecked_mut<I>(self, index: I) -> NonNull<I::Output>
pub const unsafe fn get_unchecked_mut<I>(self, index: I) -> NonNull<I::Output>
where
I: SliceIndex<[T]>,
I: ~const SliceIndex<[T]>,
{
// SAFETY: the caller ensures that `self` is dereferenceable and `index` in-bounds.
// As a consequence, the resulting pointer cannot be null.

View File

@ -1,12 +1,14 @@
//! Indexing implementations for `[T]`.
use crate::intrinsics::const_eval_select;
use crate::ops;
use crate::ptr;
#[stable(feature = "rust1", since = "1.0.0")]
impl<T, I> ops::Index<I> for [T]
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
impl<T, I> const ops::Index<I> for [T]
where
I: SliceIndex<[T]>,
I: ~const SliceIndex<[T]>,
{
type Output = I::Output;
@ -17,9 +19,10 @@ fn index(&self, index: I) -> &I::Output {
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<T, I> ops::IndexMut<I> for [T]
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
impl<T, I> const ops::IndexMut<I> for [T]
where
I: SliceIndex<[T]>,
I: ~const SliceIndex<[T]>,
{
#[inline]
fn index_mut(&mut self, index: I) -> &mut I::Output {
@ -31,31 +34,72 @@ fn index_mut(&mut self, index: I) -> &mut I::Output {
#[cfg_attr(feature = "panic_immediate_abort", inline)]
#[cold]
#[track_caller]
fn slice_start_index_len_fail(index: usize, len: usize) -> ! {
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
const fn slice_start_index_len_fail(index: usize, len: usize) -> ! {
// SAFETY: we are just panicking here
unsafe {
const_eval_select(
(index, len),
slice_start_index_len_fail_ct,
slice_start_index_len_fail_rt,
)
}
}
// FIXME const-hack
fn slice_start_index_len_fail_rt(index: usize, len: usize) -> ! {
panic!("range start index {} out of range for slice of length {}", index, len);
}
const fn slice_start_index_len_fail_ct(_: usize, _: usize) -> ! {
panic!("slice start index is out of range for slice");
}
#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))]
#[cfg_attr(feature = "panic_immediate_abort", inline)]
#[cold]
#[track_caller]
fn slice_end_index_len_fail(index: usize, len: usize) -> ! {
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
const fn slice_end_index_len_fail(index: usize, len: usize) -> ! {
// SAFETY: we are just panicking here
unsafe {
const_eval_select((index, len), slice_end_index_len_fail_ct, slice_end_index_len_fail_rt)
}
}
// FIXME const-hack
fn slice_end_index_len_fail_rt(index: usize, len: usize) -> ! {
panic!("range end index {} out of range for slice of length {}", index, len);
}
#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))]
#[cfg_attr(feature = "panic_immediate_abort", inline)]
#[cold]
#[track_caller]
fn slice_index_order_fail(index: usize, end: usize) -> ! {
panic!("slice index starts at {} but ends at {}", index, end);
const fn slice_end_index_len_fail_ct(_: usize, _: usize) -> ! {
panic!("slice end index is out of range for slice");
}
#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))]
#[cfg_attr(feature = "panic_immediate_abort", inline)]
#[cold]
#[track_caller]
fn slice_start_index_overflow_fail() -> ! {
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
const fn slice_index_order_fail(index: usize, end: usize) -> ! {
// SAFETY: we are just panicking here
unsafe { const_eval_select((index, end), slice_index_order_fail_ct, slice_index_order_fail_rt) }
}
// FIXME const-hack
fn slice_index_order_fail_rt(index: usize, end: usize) -> ! {
panic!("slice index starts at {} but ends at {}", index, end);
}
const fn slice_index_order_fail_ct(_: usize, _: usize) -> ! {
panic!("slice index start is larger than end");
}
#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))]
#[cfg_attr(feature = "panic_immediate_abort", inline)]
#[cold]
#[track_caller]
const fn slice_start_index_overflow_fail() -> ! {
panic!("attempted to index slice from after maximum usize");
}
@ -63,7 +107,7 @@ fn slice_start_index_overflow_fail() -> ! {
#[cfg_attr(feature = "panic_immediate_abort", inline)]
#[cold]
#[track_caller]
fn slice_end_index_overflow_fail() -> ! {
const fn slice_end_index_overflow_fail() -> ! {
panic!("attempted to index slice up to maximum usize");
}
@ -153,7 +197,8 @@ pub unsafe trait SliceIndex<T: ?Sized>: private_slice_index::Sealed {
}
#[stable(feature = "slice_get_slice_impls", since = "1.15.0")]
unsafe impl<T> SliceIndex<[T]> for usize {
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
unsafe impl<T> const SliceIndex<[T]> for usize {
type Output = T;
#[inline]
@ -197,7 +242,8 @@ fn index_mut(self, slice: &mut [T]) -> &mut T {
}
#[stable(feature = "slice_get_slice_impls", since = "1.15.0")]
unsafe impl<T> SliceIndex<[T]> for ops::Range<usize> {
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
unsafe impl<T> const SliceIndex<[T]> for ops::Range<usize> {
type Output = [T];
#[inline]
@ -261,7 +307,8 @@ fn index_mut(self, slice: &mut [T]) -> &mut [T] {
}
#[stable(feature = "slice_get_slice_impls", since = "1.15.0")]
unsafe impl<T> SliceIndex<[T]> for ops::RangeTo<usize> {
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
unsafe impl<T> const SliceIndex<[T]> for ops::RangeTo<usize> {
type Output = [T];
#[inline]
@ -298,7 +345,8 @@ fn index_mut(self, slice: &mut [T]) -> &mut [T] {
}
#[stable(feature = "slice_get_slice_impls", since = "1.15.0")]
unsafe impl<T> SliceIndex<[T]> for ops::RangeFrom<usize> {
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
unsafe impl<T> const SliceIndex<[T]> for ops::RangeFrom<usize> {
type Output = [T];
#[inline]
@ -343,7 +391,8 @@ fn index_mut(self, slice: &mut [T]) -> &mut [T] {
}
#[stable(feature = "slice_get_slice_impls", since = "1.15.0")]
unsafe impl<T> SliceIndex<[T]> for ops::RangeFull {
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
unsafe impl<T> const SliceIndex<[T]> for ops::RangeFull {
type Output = [T];
#[inline]
@ -378,7 +427,8 @@ fn index_mut(self, slice: &mut [T]) -> &mut [T] {
}
#[stable(feature = "inclusive_range", since = "1.26.0")]
unsafe impl<T> SliceIndex<[T]> for ops::RangeInclusive<usize> {
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
unsafe impl<T> const SliceIndex<[T]> for ops::RangeInclusive<usize> {
type Output = [T];
#[inline]
@ -421,7 +471,8 @@ fn index_mut(self, slice: &mut [T]) -> &mut [T] {
}
#[stable(feature = "inclusive_range", since = "1.26.0")]
unsafe impl<T> SliceIndex<[T]> for ops::RangeToInclusive<usize> {
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
unsafe impl<T> const SliceIndex<[T]> for ops::RangeToInclusive<usize> {
type Output = [T];
#[inline]

View File

@ -324,10 +324,11 @@ pub const fn last_mut(&mut self) -> Option<&mut T> {
/// assert_eq!(None, v.get(0..4));
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
#[inline]
pub fn get<I>(&self, index: I) -> Option<&I::Output>
pub const fn get<I>(&self, index: I) -> Option<&I::Output>
where
I: SliceIndex<Self>,
I: ~const SliceIndex<Self>,
{
index.get(self)
}
@ -348,10 +349,11 @@ pub fn get<I>(&self, index: I) -> Option<&I::Output>
/// assert_eq!(x, &[0, 42, 2]);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
#[inline]
pub fn get_mut<I>(&mut self, index: I) -> Option<&mut I::Output>
pub const fn get_mut<I>(&mut self, index: I) -> Option<&mut I::Output>
where
I: SliceIndex<Self>,
I: ~const SliceIndex<Self>,
{
index.get_mut(self)
}
@ -379,10 +381,11 @@ pub fn get_mut<I>(&mut self, index: I) -> Option<&mut I::Output>
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
#[inline]
pub unsafe fn get_unchecked<I>(&self, index: I) -> &I::Output
pub const unsafe fn get_unchecked<I>(&self, index: I) -> &I::Output
where
I: SliceIndex<Self>,
I: ~const SliceIndex<Self>,
{
// SAFETY: the caller must uphold most of the safety requirements for `get_unchecked`;
// the slice is dereferenceable because `self` is a safe reference.
@ -415,10 +418,11 @@ pub unsafe fn get_unchecked<I>(&self, index: I) -> &I::Output
/// assert_eq!(x, &[1, 13, 4]);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
#[inline]
pub unsafe fn get_unchecked_mut<I>(&mut self, index: I) -> &mut I::Output
pub const unsafe fn get_unchecked_mut<I>(&mut self, index: I) -> &mut I::Output
where
I: SliceIndex<Self>,
I: ~const SliceIndex<Self>,
{
// SAFETY: the caller must uphold the safety requirements for `get_unchecked_mut`;
// the slice is dereferenceable because `self` is a safe reference.

View File

@ -79,7 +79,23 @@
#[inline(never)]
#[cold]
#[track_caller]
fn slice_error_fail(s: &str, begin: usize, end: usize) -> ! {
#[rustc_allow_const_fn_unstable(const_eval_select)]
const fn slice_error_fail(s: &str, begin: usize, end: usize) -> ! {
// SAFETY: panics for both branches
unsafe {
crate::intrinsics::const_eval_select(
(s, begin, end),
slice_error_fail_ct,
slice_error_fail_rt,
)
}
}
const fn slice_error_fail_ct(_: &str, _: usize, _: usize) -> ! {
panic!("failed to slice string");
}
fn slice_error_fail_rt(s: &str, begin: usize, end: usize) -> ! {
const MAX_DISPLAY_LENGTH: usize = 256;
let trunc_len = s.floor_char_boundary(MAX_DISPLAY_LENGTH);
let s_trunc = &s[..trunc_len];
@ -189,8 +205,9 @@ pub const fn is_empty(&self) -> bool {
/// ```
#[must_use]
#[stable(feature = "is_char_boundary", since = "1.9.0")]
#[rustc_const_unstable(feature = "const_is_char_boundary", issue = "none")]
#[inline]
pub fn is_char_boundary(&self, index: usize) -> bool {
pub const fn is_char_boundary(&self, index: usize) -> bool {
// 0 is always ok.
// Test for 0 explicitly so that it can optimize out the check
// easily and skip reading string data for that case.
@ -418,8 +435,9 @@ pub fn as_mut_ptr(&mut self) -> *mut u8 {
/// assert!(v.get(..42).is_none());
/// ```
#[stable(feature = "str_checked_slicing", since = "1.20.0")]
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
#[inline]
pub fn get<I: SliceIndex<str>>(&self, i: I) -> Option<&I::Output> {
pub const fn get<I: ~const SliceIndex<str>>(&self, i: I) -> Option<&I::Output> {
i.get(self)
}
@ -450,8 +468,9 @@ pub fn get<I: SliceIndex<str>>(&self, i: I) -> Option<&I::Output> {
/// assert_eq!("HEllo", v);
/// ```
#[stable(feature = "str_checked_slicing", since = "1.20.0")]
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
#[inline]
pub fn get_mut<I: SliceIndex<str>>(&mut self, i: I) -> Option<&mut I::Output> {
pub const fn get_mut<I: ~const SliceIndex<str>>(&mut self, i: I) -> Option<&mut I::Output> {
i.get_mut(self)
}
@ -482,8 +501,9 @@ pub fn get_mut<I: SliceIndex<str>>(&mut self, i: I) -> Option<&mut I::Output> {
/// }
/// ```
#[stable(feature = "str_checked_slicing", since = "1.20.0")]
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
#[inline]
pub unsafe fn get_unchecked<I: SliceIndex<str>>(&self, i: I) -> &I::Output {
pub const unsafe fn get_unchecked<I: ~const SliceIndex<str>>(&self, i: I) -> &I::Output {
// SAFETY: the caller must uphold the safety contract for `get_unchecked`;
// the slice is dereferenceable because `self` is a safe reference.
// The returned pointer is safe because impls of `SliceIndex` have to guarantee that it is.
@ -517,8 +537,12 @@ pub unsafe fn get_unchecked<I: SliceIndex<str>>(&self, i: I) -> &I::Output {
/// }
/// ```
#[stable(feature = "str_checked_slicing", since = "1.20.0")]
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
#[inline]
pub unsafe fn get_unchecked_mut<I: SliceIndex<str>>(&mut self, i: I) -> &mut I::Output {
pub const unsafe fn get_unchecked_mut<I: ~const SliceIndex<str>>(
&mut self,
i: I,
) -> &mut I::Output {
// SAFETY: the caller must uphold the safety contract for `get_unchecked_mut`;
// the slice is dereferenceable because `self` is a safe reference.
// The returned pointer is safe because impls of `SliceIndex` have to guarantee that it is.

View File

@ -53,9 +53,10 @@ fn partial_cmp(&self, other: &str) -> Option<Ordering> {
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<I> ops::Index<I> for str
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
impl<I> const ops::Index<I> for str
where
I: SliceIndex<str>,
I: ~const SliceIndex<str>,
{
type Output = I::Output;
@ -66,9 +67,10 @@ fn index(&self, index: I) -> &I::Output {
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<I> ops::IndexMut<I> for str
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
impl<I> const ops::IndexMut<I> for str
where
I: SliceIndex<str>,
I: ~const SliceIndex<str>,
{
#[inline]
fn index_mut(&mut self, index: I) -> &mut I::Output {
@ -79,7 +81,7 @@ fn index_mut(&mut self, index: I) -> &mut I::Output {
#[inline(never)]
#[cold]
#[track_caller]
fn str_index_overflow_fail() -> ! {
const fn str_index_overflow_fail() -> ! {
panic!("attempted to index str up to maximum usize");
}
@ -96,7 +98,8 @@ fn str_index_overflow_fail() -> ! {
///
/// Equivalent to `&self[0 .. len]` or `&mut self[0 .. len]`.
#[stable(feature = "str_checked_slicing", since = "1.20.0")]
unsafe impl SliceIndex<str> for ops::RangeFull {
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
unsafe impl const SliceIndex<str> for ops::RangeFull {
type Output = str;
#[inline]
fn get(self, slice: &str) -> Option<&Self::Output> {
@ -160,7 +163,8 @@ fn index_mut(self, slice: &mut str) -> &mut Self::Output {
/// // &s[3 .. 100];
/// ```
#[stable(feature = "str_checked_slicing", since = "1.20.0")]
unsafe impl SliceIndex<str> for ops::Range<usize> {
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
unsafe impl const SliceIndex<str> for ops::Range<usize> {
type Output = str;
#[inline]
fn get(self, slice: &str) -> Option<&Self::Output> {
@ -247,7 +251,8 @@ fn index_mut(self, slice: &mut str) -> &mut Self::Output {
/// Panics if `end` does not point to the starting byte offset of a
/// character (as defined by `is_char_boundary`), or if `end > len`.
#[stable(feature = "str_checked_slicing", since = "1.20.0")]
unsafe impl SliceIndex<str> for ops::RangeTo<usize> {
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
unsafe impl const SliceIndex<str> for ops::RangeTo<usize> {
type Output = str;
#[inline]
fn get(self, slice: &str) -> Option<&Self::Output> {
@ -317,7 +322,8 @@ fn index_mut(self, slice: &mut str) -> &mut Self::Output {
/// Panics if `begin` does not point to the starting byte offset of
/// a character (as defined by `is_char_boundary`), or if `begin > len`.
#[stable(feature = "str_checked_slicing", since = "1.20.0")]
unsafe impl SliceIndex<str> for ops::RangeFrom<usize> {
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
unsafe impl const SliceIndex<str> for ops::RangeFrom<usize> {
type Output = str;
#[inline]
fn get(self, slice: &str) -> Option<&Self::Output> {
@ -393,7 +399,8 @@ fn index_mut(self, slice: &mut str) -> &mut Self::Output {
/// to the ending byte offset of a character (`end + 1` is either a starting
/// byte offset or equal to `len`), if `begin > end`, or if `end >= len`.
#[stable(feature = "inclusive_range", since = "1.26.0")]
unsafe impl SliceIndex<str> for ops::RangeInclusive<usize> {
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
unsafe impl const SliceIndex<str> for ops::RangeInclusive<usize> {
type Output = str;
#[inline]
fn get(self, slice: &str) -> Option<&Self::Output> {
@ -444,7 +451,8 @@ fn index_mut(self, slice: &mut str) -> &mut Self::Output {
/// (`end + 1` is either a starting byte offset as defined by
/// `is_char_boundary`, or equal to `len`), or if `end >= len`.
#[stable(feature = "inclusive_range", since = "1.26.0")]
unsafe impl SliceIndex<str> for ops::RangeToInclusive<usize> {
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
unsafe impl const SliceIndex<str> for ops::RangeToInclusive<usize> {
type Output = str;
#[inline]
fn get(self, slice: &str) -> Option<&Self::Output> {

View File

@ -23,8 +23,8 @@ LL | let _ = s.get(4);
note: required by a bound in `core::str::<impl str>::get`
--> $SRC_DIR/core/src/str/mod.rs:LL:COL
|
LL | pub fn get<I: SliceIndex<str>>(&self, i: I) -> Option<&I::Output> {
| ^^^^^^^^^^^^^^^ required by this bound in `core::str::<impl str>::get`
LL | pub const fn get<I: ~const SliceIndex<str>>(&self, i: I) -> Option<&I::Output> {
| ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `core::str::<impl str>::get`
error[E0277]: the type `str` cannot be indexed by `{integer}`
--> $DIR/str-idx.rs:5:29
@ -40,8 +40,8 @@ LL | let _ = s.get_unchecked(4);
note: required by a bound in `core::str::<impl str>::get_unchecked`
--> $SRC_DIR/core/src/str/mod.rs:LL:COL
|
LL | pub unsafe fn get_unchecked<I: SliceIndex<str>>(&self, i: I) -> &I::Output {
| ^^^^^^^^^^^^^^^ required by this bound in `core::str::<impl str>::get_unchecked`
LL | pub const unsafe fn get_unchecked<I: ~const SliceIndex<str>>(&self, i: I) -> &I::Output {
| ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `core::str::<impl str>::get_unchecked`
error[E0277]: the type `str` cannot be indexed by `char`
--> $DIR/str-idx.rs:6:17

View File

@ -47,8 +47,8 @@ LL | s.get_mut(1);
note: required by a bound in `core::str::<impl str>::get_mut`
--> $SRC_DIR/core/src/str/mod.rs:LL:COL
|
LL | pub fn get_mut<I: SliceIndex<str>>(&mut self, i: I) -> Option<&mut I::Output> {
| ^^^^^^^^^^^^^^^ required by this bound in `core::str::<impl str>::get_mut`
LL | pub const fn get_mut<I: ~const SliceIndex<str>>(&mut self, i: I) -> Option<&mut I::Output> {
| ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `core::str::<impl str>::get_mut`
error[E0277]: the type `str` cannot be indexed by `{integer}`
--> $DIR/str-mut-idx.rs:11:25
@ -64,8 +64,8 @@ LL | s.get_unchecked_mut(1);
note: required by a bound in `core::str::<impl str>::get_unchecked_mut`
--> $SRC_DIR/core/src/str/mod.rs:LL:COL
|
LL | pub unsafe fn get_unchecked_mut<I: SliceIndex<str>>(&mut self, i: I) -> &mut I::Output {
| ^^^^^^^^^^^^^^^ required by this bound in `core::str::<impl str>::get_unchecked_mut`
LL | pub const unsafe fn get_unchecked_mut<I: ~const SliceIndex<str>>(
| ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `core::str::<impl str>::get_unchecked_mut`
error[E0277]: the type `str` cannot be indexed by `char`
--> $DIR/str-mut-idx.rs:13:5