Auto merge of #95274 - jendrikw:slice-must-use, r=Dylan-DPC
add #[must_use] to functions of slice and its iterators. Continuation of #92853. Tracking issue: #89692.
This commit is contained in:
commit
1d9c262eea
15 changed files with 126 additions and 49 deletions
|
@ -172,6 +172,7 @@ impl_fn_for_zst! {
|
|||
/// documentation for more information.
|
||||
#[stable(feature = "inherent_ascii_escape", since = "1.60.0")]
|
||||
#[derive(Clone)]
|
||||
#[must_use = "iterators are lazy and do nothing unless consumed"]
|
||||
pub struct EscapeAscii<'a> {
|
||||
inner: iter::FlatMap<super::Iter<'a, u8>, ascii::EscapeDefault, EscapeByte>,
|
||||
}
|
||||
|
|
|
@ -549,7 +549,7 @@ unsafe impl<T> const SliceIndex<[T]> for ops::RangeToInclusive<usize> {
|
|||
///
|
||||
/// use std::slice;
|
||||
///
|
||||
/// slice::range(2..1, ..3);
|
||||
/// let _ = slice::range(2..1, ..3);
|
||||
/// ```
|
||||
///
|
||||
/// ```should_panic
|
||||
|
@ -557,7 +557,7 @@ unsafe impl<T> const SliceIndex<[T]> for ops::RangeToInclusive<usize> {
|
|||
///
|
||||
/// use std::slice;
|
||||
///
|
||||
/// slice::range(1..4, ..3);
|
||||
/// let _ = slice::range(1..4, ..3);
|
||||
/// ```
|
||||
///
|
||||
/// ```should_panic
|
||||
|
@ -565,12 +565,13 @@ unsafe impl<T> const SliceIndex<[T]> for ops::RangeToInclusive<usize> {
|
|||
///
|
||||
/// use std::slice;
|
||||
///
|
||||
/// slice::range(1..=usize::MAX, ..3);
|
||||
/// let _ = slice::range(1..=usize::MAX, ..3);
|
||||
/// ```
|
||||
///
|
||||
/// [`Index::index`]: ops::Index::index
|
||||
#[track_caller]
|
||||
#[unstable(feature = "slice_range", issue = "76393")]
|
||||
#[must_use]
|
||||
pub fn range<R>(range: R, bounds: ops::RangeTo<usize>) -> ops::Range<usize>
|
||||
where
|
||||
R: ops::RangeBounds<usize>,
|
||||
|
|
|
@ -62,6 +62,7 @@ fn size_from_ptr<T>(_: *const T) -> usize {
|
|||
/// [`iter`]: slice::iter
|
||||
/// [slices]: slice
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[must_use = "iterators are lazy and do nothing unless consumed"]
|
||||
pub struct Iter<'a, T: 'a> {
|
||||
ptr: NonNull<T>,
|
||||
end: *const T, // If T is a ZST, this is actually ptr+len. This encoding is picked so that
|
||||
|
@ -182,6 +183,7 @@ impl<T> AsRef<[T]> for Iter<'_, T> {
|
|||
/// [`iter_mut`]: slice::iter_mut
|
||||
/// [slices]: slice
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[must_use = "iterators are lazy and do nothing unless consumed"]
|
||||
pub struct IterMut<'a, T: 'a> {
|
||||
ptr: NonNull<T>,
|
||||
end: *mut T, // If T is a ZST, this is actually ptr+len. This encoding is picked so that
|
||||
|
@ -339,6 +341,7 @@ pub(super) trait SplitIter: DoubleEndedIterator {
|
|||
/// [`split`]: slice::split
|
||||
/// [slices]: slice
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[must_use = "iterators are lazy and do nothing unless consumed"]
|
||||
pub struct Split<'a, T: 'a, P>
|
||||
where
|
||||
P: FnMut(&T) -> bool,
|
||||
|
@ -469,6 +472,7 @@ impl<T, P> FusedIterator for Split<'_, T, P> where P: FnMut(&T) -> bool {}
|
|||
/// [`split_inclusive`]: slice::split_inclusive
|
||||
/// [slices]: slice
|
||||
#[stable(feature = "split_inclusive", since = "1.51.0")]
|
||||
#[must_use = "iterators are lazy and do nothing unless consumed"]
|
||||
pub struct SplitInclusive<'a, T: 'a, P>
|
||||
where
|
||||
P: FnMut(&T) -> bool,
|
||||
|
@ -589,6 +593,7 @@ impl<T, P> FusedIterator for SplitInclusive<'_, T, P> where P: FnMut(&T) -> bool
|
|||
/// [`split_mut`]: slice::split_mut
|
||||
/// [slices]: slice
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[must_use = "iterators are lazy and do nothing unless consumed"]
|
||||
pub struct SplitMut<'a, T: 'a, P>
|
||||
where
|
||||
P: FnMut(&T) -> bool,
|
||||
|
@ -718,6 +723,7 @@ impl<T, P> FusedIterator for SplitMut<'_, T, P> where P: FnMut(&T) -> bool {}
|
|||
/// [`split_inclusive_mut`]: slice::split_inclusive_mut
|
||||
/// [slices]: slice
|
||||
#[stable(feature = "split_inclusive", since = "1.51.0")]
|
||||
#[must_use = "iterators are lazy and do nothing unless consumed"]
|
||||
pub struct SplitInclusiveMut<'a, T: 'a, P>
|
||||
where
|
||||
P: FnMut(&T) -> bool,
|
||||
|
@ -841,6 +847,7 @@ impl<T, P> FusedIterator for SplitInclusiveMut<'_, T, P> where P: FnMut(&T) -> b
|
|||
/// [`rsplit`]: slice::rsplit
|
||||
/// [slices]: slice
|
||||
#[stable(feature = "slice_rsplit", since = "1.27.0")]
|
||||
#[must_use = "iterators are lazy and do nothing unless consumed"]
|
||||
pub struct RSplit<'a, T: 'a, P>
|
||||
where
|
||||
P: FnMut(&T) -> bool,
|
||||
|
@ -937,6 +944,7 @@ impl<T, P> FusedIterator for RSplit<'_, T, P> where P: FnMut(&T) -> bool {}
|
|||
/// [`rsplit_mut`]: slice::rsplit_mut
|
||||
/// [slices]: slice
|
||||
#[stable(feature = "slice_rsplit", since = "1.27.0")]
|
||||
#[must_use = "iterators are lazy and do nothing unless consumed"]
|
||||
pub struct RSplitMut<'a, T: 'a, P>
|
||||
where
|
||||
P: FnMut(&T) -> bool,
|
||||
|
@ -1059,6 +1067,7 @@ impl<T, I: SplitIter<Item = T>> Iterator for GenericSplitN<I> {
|
|||
/// [`splitn`]: slice::splitn
|
||||
/// [slices]: slice
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[must_use = "iterators are lazy and do nothing unless consumed"]
|
||||
pub struct SplitN<'a, T: 'a, P>
|
||||
where
|
||||
P: FnMut(&T) -> bool,
|
||||
|
@ -1099,6 +1108,7 @@ where
|
|||
/// [`rsplitn`]: slice::rsplitn
|
||||
/// [slices]: slice
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[must_use = "iterators are lazy and do nothing unless consumed"]
|
||||
pub struct RSplitN<'a, T: 'a, P>
|
||||
where
|
||||
P: FnMut(&T) -> bool,
|
||||
|
@ -1138,6 +1148,7 @@ where
|
|||
/// [`splitn_mut`]: slice::splitn_mut
|
||||
/// [slices]: slice
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[must_use = "iterators are lazy and do nothing unless consumed"]
|
||||
pub struct SplitNMut<'a, T: 'a, P>
|
||||
where
|
||||
P: FnMut(&T) -> bool,
|
||||
|
@ -1178,6 +1189,7 @@ where
|
|||
/// [`rsplitn_mut`]: slice::rsplitn_mut
|
||||
/// [slices]: slice
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[must_use = "iterators are lazy and do nothing unless consumed"]
|
||||
pub struct RSplitNMut<'a, T: 'a, P>
|
||||
where
|
||||
P: FnMut(&T) -> bool,
|
||||
|
@ -1222,6 +1234,7 @@ forward_iterator! { RSplitNMut: T, &'a mut [T] }
|
|||
/// [slices]: slice
|
||||
#[derive(Debug)]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[must_use = "iterators are lazy and do nothing unless consumed"]
|
||||
pub struct Windows<'a, T: 'a> {
|
||||
v: &'a [T],
|
||||
size: NonZeroUsize,
|
||||
|
@ -1370,6 +1383,7 @@ unsafe impl<'a, T> TrustedRandomAccessNoCoerce for Windows<'a, T> {
|
|||
/// [slices]: slice
|
||||
#[derive(Debug)]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[must_use = "iterators are lazy and do nothing unless consumed"]
|
||||
pub struct Chunks<'a, T: 'a> {
|
||||
v: &'a [T],
|
||||
chunk_size: usize,
|
||||
|
@ -1553,6 +1567,7 @@ unsafe impl<'a, T> TrustedRandomAccessNoCoerce for Chunks<'a, T> {
|
|||
/// [slices]: slice
|
||||
#[derive(Debug)]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[must_use = "iterators are lazy and do nothing unless consumed"]
|
||||
pub struct ChunksMut<'a, T: 'a> {
|
||||
v: &'a mut [T],
|
||||
chunk_size: usize,
|
||||
|
@ -1722,6 +1737,7 @@ unsafe impl<'a, T> TrustedRandomAccessNoCoerce for ChunksMut<'a, T> {
|
|||
/// [slices]: slice
|
||||
#[derive(Debug)]
|
||||
#[stable(feature = "chunks_exact", since = "1.31.0")]
|
||||
#[must_use = "iterators are lazy and do nothing unless consumed"]
|
||||
pub struct ChunksExact<'a, T: 'a> {
|
||||
v: &'a [T],
|
||||
rem: &'a [T],
|
||||
|
@ -1881,6 +1897,7 @@ unsafe impl<'a, T> TrustedRandomAccessNoCoerce for ChunksExact<'a, T> {
|
|||
/// [slices]: slice
|
||||
#[derive(Debug)]
|
||||
#[stable(feature = "chunks_exact", since = "1.31.0")]
|
||||
#[must_use = "iterators are lazy and do nothing unless consumed"]
|
||||
pub struct ChunksExactMut<'a, T: 'a> {
|
||||
v: &'a mut [T],
|
||||
rem: &'a mut [T],
|
||||
|
@ -2034,6 +2051,7 @@ unsafe impl<'a, T> TrustedRandomAccessNoCoerce for ChunksExactMut<'a, T> {
|
|||
/// [slices]: slice
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
#[unstable(feature = "array_windows", issue = "75027")]
|
||||
#[must_use = "iterators are lazy and do nothing unless consumed"]
|
||||
pub struct ArrayWindows<'a, T: 'a, const N: usize> {
|
||||
slice_head: *const T,
|
||||
num: usize,
|
||||
|
@ -2156,6 +2174,7 @@ impl<T, const N: usize> ExactSizeIterator for ArrayWindows<'_, T, N> {
|
|||
/// [slices]: slice
|
||||
#[derive(Debug)]
|
||||
#[unstable(feature = "array_chunks", issue = "74985")]
|
||||
#[must_use = "iterators are lazy and do nothing unless consumed"]
|
||||
pub struct ArrayChunks<'a, T: 'a, const N: usize> {
|
||||
iter: Iter<'a, [T; N]>,
|
||||
rem: &'a [T],
|
||||
|
@ -2282,6 +2301,7 @@ unsafe impl<'a, T, const N: usize> TrustedRandomAccessNoCoerce for ArrayChunks<'
|
|||
/// [slices]: slice
|
||||
#[derive(Debug)]
|
||||
#[unstable(feature = "array_chunks", issue = "74985")]
|
||||
#[must_use = "iterators are lazy and do nothing unless consumed"]
|
||||
pub struct ArrayChunksMut<'a, T: 'a, const N: usize> {
|
||||
iter: IterMut<'a, [T; N]>,
|
||||
rem: &'a mut [T],
|
||||
|
@ -2396,6 +2416,7 @@ unsafe impl<'a, T, const N: usize> TrustedRandomAccessNoCoerce for ArrayChunksMu
|
|||
/// [slices]: slice
|
||||
#[derive(Debug)]
|
||||
#[stable(feature = "rchunks", since = "1.31.0")]
|
||||
#[must_use = "iterators are lazy and do nothing unless consumed"]
|
||||
pub struct RChunks<'a, T: 'a> {
|
||||
v: &'a [T],
|
||||
chunk_size: usize,
|
||||
|
@ -2569,6 +2590,7 @@ unsafe impl<'a, T> TrustedRandomAccessNoCoerce for RChunks<'a, T> {
|
|||
/// [slices]: slice
|
||||
#[derive(Debug)]
|
||||
#[stable(feature = "rchunks", since = "1.31.0")]
|
||||
#[must_use = "iterators are lazy and do nothing unless consumed"]
|
||||
pub struct RChunksMut<'a, T: 'a> {
|
||||
v: &'a mut [T],
|
||||
chunk_size: usize,
|
||||
|
@ -2742,6 +2764,7 @@ unsafe impl<'a, T> TrustedRandomAccessNoCoerce for RChunksMut<'a, T> {
|
|||
/// [slices]: slice
|
||||
#[derive(Debug)]
|
||||
#[stable(feature = "rchunks", since = "1.31.0")]
|
||||
#[must_use = "iterators are lazy and do nothing unless consumed"]
|
||||
pub struct RChunksExact<'a, T: 'a> {
|
||||
v: &'a [T],
|
||||
rem: &'a [T],
|
||||
|
@ -2905,6 +2928,7 @@ unsafe impl<'a, T> TrustedRandomAccessNoCoerce for RChunksExact<'a, T> {
|
|||
/// [slices]: slice
|
||||
#[derive(Debug)]
|
||||
#[stable(feature = "rchunks", since = "1.31.0")]
|
||||
#[must_use = "iterators are lazy and do nothing unless consumed"]
|
||||
pub struct RChunksExactMut<'a, T: 'a> {
|
||||
v: &'a mut [T],
|
||||
rem: &'a mut [T],
|
||||
|
@ -3071,6 +3095,7 @@ unsafe impl<'a, T> TrustedRandomAccessNoCoerce for IterMut<'a, T> {
|
|||
/// [`group_by`]: slice::group_by
|
||||
/// [slices]: slice
|
||||
#[unstable(feature = "slice_group_by", issue = "80552")]
|
||||
#[must_use = "iterators are lazy and do nothing unless consumed"]
|
||||
pub struct GroupBy<'a, T: 'a, P> {
|
||||
slice: &'a [T],
|
||||
predicate: P,
|
||||
|
@ -3157,6 +3182,7 @@ impl<'a, T: 'a + fmt::Debug, P> fmt::Debug for GroupBy<'a, T, P> {
|
|||
/// [`group_by_mut`]: slice::group_by_mut
|
||||
/// [slices]: slice
|
||||
#[unstable(feature = "slice_group_by", issue = "80552")]
|
||||
#[must_use = "iterators are lazy and do nothing unless consumed"]
|
||||
pub struct GroupByMut<'a, T: 'a, P> {
|
||||
slice: &'a mut [T],
|
||||
predicate: P,
|
||||
|
|
|
@ -124,6 +124,7 @@ impl<T> [T] {
|
|||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_stable(feature = "const_slice_len", since = "1.39.0")]
|
||||
#[inline]
|
||||
#[must_use]
|
||||
// SAFETY: const sound because we transmute out the length field as a usize (which it must be)
|
||||
pub const fn len(&self) -> usize {
|
||||
// FIXME: Replace with `crate::ptr::metadata(self)` when that is const-stable.
|
||||
|
@ -147,6 +148,7 @@ impl<T> [T] {
|
|||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_stable(feature = "const_slice_is_empty", since = "1.39.0")]
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub const fn is_empty(&self) -> bool {
|
||||
self.len() == 0
|
||||
}
|
||||
|
@ -165,6 +167,7 @@ impl<T> [T] {
|
|||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_stable(feature = "const_slice_first_last_not_mut", since = "1.56.0")]
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub const fn first(&self) -> Option<&T> {
|
||||
if let [first, ..] = self { Some(first) } else { None }
|
||||
}
|
||||
|
@ -184,6 +187,7 @@ impl<T> [T] {
|
|||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_slice_first_last", issue = "83570")]
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub const fn first_mut(&mut self) -> Option<&mut T> {
|
||||
if let [first, ..] = self { Some(first) } else { None }
|
||||
}
|
||||
|
@ -203,6 +207,7 @@ impl<T> [T] {
|
|||
#[stable(feature = "slice_splits", since = "1.5.0")]
|
||||
#[rustc_const_stable(feature = "const_slice_first_last_not_mut", since = "1.56.0")]
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub const fn split_first(&self) -> Option<(&T, &[T])> {
|
||||
if let [first, tail @ ..] = self { Some((first, tail)) } else { None }
|
||||
}
|
||||
|
@ -224,6 +229,7 @@ impl<T> [T] {
|
|||
#[stable(feature = "slice_splits", since = "1.5.0")]
|
||||
#[rustc_const_unstable(feature = "const_slice_first_last", issue = "83570")]
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub const fn split_first_mut(&mut self) -> Option<(&mut T, &mut [T])> {
|
||||
if let [first, tail @ ..] = self { Some((first, tail)) } else { None }
|
||||
}
|
||||
|
@ -243,6 +249,7 @@ impl<T> [T] {
|
|||
#[stable(feature = "slice_splits", since = "1.5.0")]
|
||||
#[rustc_const_stable(feature = "const_slice_first_last_not_mut", since = "1.56.0")]
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub const fn split_last(&self) -> Option<(&T, &[T])> {
|
||||
if let [init @ .., last] = self { Some((last, init)) } else { None }
|
||||
}
|
||||
|
@ -264,6 +271,7 @@ impl<T> [T] {
|
|||
#[stable(feature = "slice_splits", since = "1.5.0")]
|
||||
#[rustc_const_unstable(feature = "const_slice_first_last", issue = "83570")]
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub const fn split_last_mut(&mut self) -> Option<(&mut T, &mut [T])> {
|
||||
if let [init @ .., last] = self { Some((last, init)) } else { None }
|
||||
}
|
||||
|
@ -282,6 +290,7 @@ impl<T> [T] {
|
|||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_stable(feature = "const_slice_first_last_not_mut", since = "1.56.0")]
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub const fn last(&self) -> Option<&T> {
|
||||
if let [.., last] = self { Some(last) } else { None }
|
||||
}
|
||||
|
@ -301,6 +310,7 @@ impl<T> [T] {
|
|||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_slice_first_last", issue = "83570")]
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub const fn last_mut(&mut self) -> Option<&mut T> {
|
||||
if let [.., last] = self { Some(last) } else { None }
|
||||
}
|
||||
|
@ -325,6 +335,7 @@ impl<T> [T] {
|
|||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub const fn get<I>(&self, index: I) -> Option<&I::Output>
|
||||
where
|
||||
I: ~const SliceIndex<Self>,
|
||||
|
@ -350,6 +361,7 @@ impl<T> [T] {
|
|||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub const fn get_mut<I>(&mut self, index: I) -> Option<&mut I::Output>
|
||||
where
|
||||
I: ~const SliceIndex<Self>,
|
||||
|
@ -382,6 +394,7 @@ impl<T> [T] {
|
|||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub const unsafe fn get_unchecked<I>(&self, index: I) -> &I::Output
|
||||
where
|
||||
I: ~const SliceIndex<Self>,
|
||||
|
@ -419,6 +432,7 @@ impl<T> [T] {
|
|||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub const unsafe fn get_unchecked_mut<I>(&mut self, index: I) -> &mut I::Output
|
||||
where
|
||||
I: ~const SliceIndex<Self>,
|
||||
|
@ -458,6 +472,7 @@ impl<T> [T] {
|
|||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_stable(feature = "const_slice_as_ptr", since = "1.32.0")]
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub const fn as_ptr(&self) -> *const T {
|
||||
self as *const [T] as *const T
|
||||
}
|
||||
|
@ -486,6 +501,7 @@ impl<T> [T] {
|
|||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_ptr_offset", issue = "71499")]
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub const fn as_mut_ptr(&mut self) -> *mut T {
|
||||
self as *mut [T] as *mut T
|
||||
}
|
||||
|
@ -521,6 +537,7 @@ impl<T> [T] {
|
|||
#[stable(feature = "slice_ptr_range", since = "1.48.0")]
|
||||
#[rustc_const_unstable(feature = "const_ptr_offset", issue = "71499")]
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub const fn as_ptr_range(&self) -> Range<*const T> {
|
||||
let start = self.as_ptr();
|
||||
// SAFETY: The `add` here is safe, because:
|
||||
|
@ -563,6 +580,7 @@ impl<T> [T] {
|
|||
#[stable(feature = "slice_ptr_range", since = "1.48.0")]
|
||||
#[rustc_const_unstable(feature = "const_ptr_offset", issue = "71499")]
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub const fn as_mut_ptr_range(&mut self) -> Range<*mut T> {
|
||||
let start = self.as_mut_ptr();
|
||||
// SAFETY: See as_ptr_range() above for why `add` here is safe.
|
||||
|
@ -948,6 +966,7 @@ impl<T> [T] {
|
|||
/// ```
|
||||
#[unstable(feature = "slice_as_chunks", issue = "74985")]
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub unsafe fn as_chunks_unchecked<const N: usize>(&self) -> &[[T; N]] {
|
||||
debug_assert_ne!(N, 0);
|
||||
debug_assert_eq!(self.len() % N, 0);
|
||||
|
@ -979,6 +998,7 @@ impl<T> [T] {
|
|||
/// ```
|
||||
#[unstable(feature = "slice_as_chunks", issue = "74985")]
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub fn as_chunks<const N: usize>(&self) -> (&[[T; N]], &[T]) {
|
||||
assert_ne!(N, 0);
|
||||
let len = self.len() / N;
|
||||
|
@ -1009,6 +1029,7 @@ impl<T> [T] {
|
|||
/// ```
|
||||
#[unstable(feature = "slice_as_chunks", issue = "74985")]
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub fn as_rchunks<const N: usize>(&self) -> (&[T], &[[T; N]]) {
|
||||
assert_ne!(N, 0);
|
||||
let len = self.len() / N;
|
||||
|
@ -1084,6 +1105,7 @@ impl<T> [T] {
|
|||
/// ```
|
||||
#[unstable(feature = "slice_as_chunks", issue = "74985")]
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub unsafe fn as_chunks_unchecked_mut<const N: usize>(&mut self) -> &mut [[T; N]] {
|
||||
debug_assert_ne!(N, 0);
|
||||
debug_assert_eq!(self.len() % N, 0);
|
||||
|
@ -1121,6 +1143,7 @@ impl<T> [T] {
|
|||
/// ```
|
||||
#[unstable(feature = "slice_as_chunks", issue = "74985")]
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub fn as_chunks_mut<const N: usize>(&mut self) -> (&mut [[T; N]], &mut [T]) {
|
||||
assert_ne!(N, 0);
|
||||
let len = self.len() / N;
|
||||
|
@ -1157,6 +1180,7 @@ impl<T> [T] {
|
|||
/// ```
|
||||
#[unstable(feature = "slice_as_chunks", issue = "74985")]
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub fn as_rchunks_mut<const N: usize>(&mut self) -> (&mut [T], &mut [[T; N]]) {
|
||||
assert_ne!(N, 0);
|
||||
let len = self.len() / N;
|
||||
|
@ -1515,6 +1539,7 @@ impl<T> [T] {
|
|||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
#[track_caller]
|
||||
#[must_use]
|
||||
pub fn split_at(&self, mid: usize) -> (&[T], &[T]) {
|
||||
assert!(mid <= self.len());
|
||||
// SAFETY: `[ptr; mid]` and `[mid; len]` are inside `self`, which
|
||||
|
@ -1546,6 +1571,7 @@ impl<T> [T] {
|
|||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
#[track_caller]
|
||||
#[must_use]
|
||||
pub fn split_at_mut(&mut self, mid: usize) -> (&mut [T], &mut [T]) {
|
||||
assert!(mid <= self.len());
|
||||
// SAFETY: `[ptr; mid]` and `[mid; len]` are inside `self`, which
|
||||
|
@ -1597,6 +1623,7 @@ impl<T> [T] {
|
|||
/// ```
|
||||
#[unstable(feature = "slice_split_at_unchecked", reason = "new API", issue = "76014")]
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub unsafe fn split_at_unchecked(&self, mid: usize) -> (&[T], &[T]) {
|
||||
// SAFETY: Caller has to check that `0 <= mid <= self.len()`
|
||||
unsafe { (self.get_unchecked(..mid), self.get_unchecked(mid..)) }
|
||||
|
@ -1637,6 +1664,7 @@ impl<T> [T] {
|
|||
/// ```
|
||||
#[unstable(feature = "slice_split_at_unchecked", reason = "new API", issue = "76014")]
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub unsafe fn split_at_mut_unchecked(&mut self, mid: usize) -> (&mut [T], &mut [T]) {
|
||||
let len = self.len();
|
||||
let ptr = self.as_mut_ptr();
|
||||
|
@ -1686,6 +1714,7 @@ impl<T> [T] {
|
|||
#[unstable(feature = "split_array", reason = "new API", issue = "90091")]
|
||||
#[inline]
|
||||
#[track_caller]
|
||||
#[must_use]
|
||||
pub fn split_array_ref<const N: usize>(&self) -> (&[T; N], &[T]) {
|
||||
let (a, b) = self.split_at(N);
|
||||
// SAFETY: a points to [T; N]? Yes it's [T] of length N (checked by split_at)
|
||||
|
@ -1718,6 +1747,7 @@ impl<T> [T] {
|
|||
#[unstable(feature = "split_array", reason = "new API", issue = "90091")]
|
||||
#[inline]
|
||||
#[track_caller]
|
||||
#[must_use]
|
||||
pub fn split_array_mut<const N: usize>(&mut self) -> (&mut [T; N], &mut [T]) {
|
||||
let (a, b) = self.split_at_mut(N);
|
||||
// SAFETY: a points to [T; N]? Yes it's [T] of length N (checked by split_at_mut)
|
||||
|
@ -1762,6 +1792,7 @@ impl<T> [T] {
|
|||
/// ```
|
||||
#[unstable(feature = "split_array", reason = "new API", issue = "90091")]
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub fn rsplit_array_ref<const N: usize>(&self) -> (&[T], &[T; N]) {
|
||||
assert!(N <= self.len());
|
||||
let (a, b) = self.split_at(self.len() - N);
|
||||
|
@ -1795,6 +1826,7 @@ impl<T> [T] {
|
|||
/// ```
|
||||
#[unstable(feature = "split_array", reason = "new API", issue = "90091")]
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub fn rsplit_array_mut<const N: usize>(&mut self) -> (&mut [T], &mut [T; N]) {
|
||||
assert!(N <= self.len());
|
||||
let (a, b) = self.split_at_mut(self.len() - N);
|
||||
|
@ -2126,6 +2158,7 @@ impl<T> [T] {
|
|||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub fn contains(&self, x: &T) -> bool
|
||||
where
|
||||
T: PartialEq,
|
||||
|
@ -2154,6 +2187,7 @@ impl<T> [T] {
|
|||
/// assert!(v.starts_with(&[]));
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[must_use]
|
||||
pub fn starts_with(&self, needle: &[T]) -> bool
|
||||
where
|
||||
T: PartialEq,
|
||||
|
@ -2183,6 +2217,7 @@ impl<T> [T] {
|
|||
/// assert!(v.ends_with(&[]));
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[must_use]
|
||||
pub fn ends_with(&self, needle: &[T]) -> bool
|
||||
where
|
||||
T: PartialEq,
|
||||
|
@ -3390,6 +3425,7 @@ impl<T> [T] {
|
|||
/// }
|
||||
/// ```
|
||||
#[stable(feature = "slice_align_to", since = "1.30.0")]
|
||||
#[must_use]
|
||||
pub unsafe fn align_to<U>(&self) -> (&[T], &[U], &[T]) {
|
||||
// Note that most of this function will be constant-evaluated,
|
||||
if mem::size_of::<U>() == 0 || mem::size_of::<T>() == 0 {
|
||||
|
@ -3450,6 +3486,7 @@ impl<T> [T] {
|
|||
/// }
|
||||
/// ```
|
||||
#[stable(feature = "slice_align_to", since = "1.30.0")]
|
||||
#[must_use]
|
||||
pub unsafe fn align_to_mut<U>(&mut self) -> (&mut [T], &mut [U], &mut [T]) {
|
||||
// Note that most of this function will be constant-evaluated,
|
||||
if mem::size_of::<U>() == 0 || mem::size_of::<T>() == 0 {
|
||||
|
@ -3543,6 +3580,7 @@ impl<T> [T] {
|
|||
/// assert_eq!(basic_simd_sum(&numbers[1..99]), 4949.0);
|
||||
/// ```
|
||||
#[unstable(feature = "portable_simd", issue = "86656")]
|
||||
#[must_use]
|
||||
pub fn as_simd<const LANES: usize>(&self) -> (&[T], &[Simd<T, LANES>], &[T])
|
||||
where
|
||||
Simd<T, LANES>: AsRef<[T; LANES]>,
|
||||
|
@ -3586,6 +3624,7 @@ impl<T> [T] {
|
|||
/// be lifted in a way that would make it possible to see panics from this
|
||||
/// method for something like `LANES == 3`.
|
||||
#[unstable(feature = "portable_simd", issue = "86656")]
|
||||
#[must_use]
|
||||
pub fn as_simd_mut<const LANES: usize>(&mut self) -> (&mut [T], &mut [Simd<T, LANES>], &mut [T])
|
||||
where
|
||||
Simd<T, LANES>: AsMut<[T; LANES]>,
|
||||
|
@ -3625,6 +3664,7 @@ impl<T> [T] {
|
|||
/// ```
|
||||
#[inline]
|
||||
#[unstable(feature = "is_sorted", reason = "new API", issue = "53485")]
|
||||
#[must_use]
|
||||
pub fn is_sorted(&self) -> bool
|
||||
where
|
||||
T: PartialOrd,
|
||||
|
@ -3640,6 +3680,7 @@ impl<T> [T] {
|
|||
///
|
||||
/// [`is_sorted`]: slice::is_sorted
|
||||
#[unstable(feature = "is_sorted", reason = "new API", issue = "53485")]
|
||||
#[must_use]
|
||||
pub fn is_sorted_by<F>(&self, mut compare: F) -> bool
|
||||
where
|
||||
F: FnMut(&T, &T) -> Option<Ordering>,
|
||||
|
@ -3665,6 +3706,7 @@ impl<T> [T] {
|
|||
/// ```
|
||||
#[inline]
|
||||
#[unstable(feature = "is_sorted", reason = "new API", issue = "53485")]
|
||||
#[must_use]
|
||||
pub fn is_sorted_by_key<F, K>(&self, f: F) -> bool
|
||||
where
|
||||
F: FnMut(&T) -> K,
|
||||
|
@ -3702,6 +3744,7 @@ impl<T> [T] {
|
|||
/// assert!(v[i..].iter().all(|&x| !(x < 5)));
|
||||
/// ```
|
||||
#[stable(feature = "partition_point", since = "1.52.0")]
|
||||
#[must_use]
|
||||
pub fn partition_point<P>(&self, mut pred: P) -> usize
|
||||
where
|
||||
P: FnMut(&T) -> bool,
|
||||
|
|
|
@ -85,6 +85,7 @@ use crate::ptr;
|
|||
#[inline]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_slice_from_raw_parts", issue = "67456")]
|
||||
#[must_use]
|
||||
pub const unsafe fn from_raw_parts<'a, T>(data: *const T, len: usize) -> &'a [T] {
|
||||
debug_check_data_len(data, len);
|
||||
|
||||
|
@ -124,6 +125,7 @@ pub const unsafe fn from_raw_parts<'a, T>(data: *const T, len: usize) -> &'a [T]
|
|||
#[inline]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_slice_from_raw_parts", issue = "67456")]
|
||||
#[must_use]
|
||||
pub const unsafe fn from_raw_parts_mut<'a, T>(data: *mut T, len: usize) -> &'a mut [T] {
|
||||
debug_check_data_len(data as _, len);
|
||||
|
||||
|
@ -168,6 +170,7 @@ const fn debug_check_data_len<T>(_data: *const T, _len: usize) {}
|
|||
/// Converts a reference to T into a slice of length 1 (without copying).
|
||||
#[stable(feature = "from_ref", since = "1.28.0")]
|
||||
#[rustc_const_unstable(feature = "const_slice_from_ref", issue = "90206")]
|
||||
#[must_use]
|
||||
pub const fn from_ref<T>(s: &T) -> &[T] {
|
||||
array::from_ref(s)
|
||||
}
|
||||
|
@ -175,6 +178,7 @@ pub const fn from_ref<T>(s: &T) -> &[T] {
|
|||
/// Converts a reference to T into a slice of length 1 (without copying).
|
||||
#[stable(feature = "from_ref", since = "1.28.0")]
|
||||
#[rustc_const_unstable(feature = "const_slice_from_ref", issue = "90206")]
|
||||
#[must_use]
|
||||
pub const fn from_mut<T>(s: &mut T) -> &mut [T] {
|
||||
array::from_mut(s)
|
||||
}
|
||||
|
|
|
@ -2344,7 +2344,7 @@ fn slice_rsplit_array_mut() {
|
|||
fn slice_split_array_ref_out_of_bounds() {
|
||||
let v = &[1, 2, 3, 4, 5, 6][..];
|
||||
|
||||
v.split_array_ref::<7>();
|
||||
let _ = v.split_array_ref::<7>();
|
||||
}
|
||||
|
||||
#[should_panic]
|
||||
|
@ -2352,7 +2352,7 @@ fn slice_split_array_ref_out_of_bounds() {
|
|||
fn slice_split_array_mut_out_of_bounds() {
|
||||
let v = &mut [1, 2, 3, 4, 5, 6][..];
|
||||
|
||||
v.split_array_mut::<7>();
|
||||
let _ = v.split_array_mut::<7>();
|
||||
}
|
||||
|
||||
#[should_panic]
|
||||
|
@ -2360,7 +2360,7 @@ fn slice_split_array_mut_out_of_bounds() {
|
|||
fn slice_rsplit_array_ref_out_of_bounds() {
|
||||
let v = &[1, 2, 3, 4, 5, 6][..];
|
||||
|
||||
v.rsplit_array_ref::<7>();
|
||||
let _ = v.rsplit_array_ref::<7>();
|
||||
}
|
||||
|
||||
#[should_panic]
|
||||
|
@ -2368,7 +2368,7 @@ fn slice_rsplit_array_ref_out_of_bounds() {
|
|||
fn slice_rsplit_array_mut_out_of_bounds() {
|
||||
let v = &mut [1, 2, 3, 4, 5, 6][..];
|
||||
|
||||
v.rsplit_array_mut::<7>();
|
||||
let _ = v.rsplit_array_mut::<7>();
|
||||
}
|
||||
|
||||
macro_rules! take_tests {
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// run-rustfix
|
||||
// rustfix-only-machine-applicable
|
||||
|
||||
#[allow(unused_must_use)]
|
||||
fn main() {
|
||||
let small = [1, 2];
|
||||
let big = [0u8; 33];
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// run-rustfix
|
||||
// rustfix-only-machine-applicable
|
||||
|
||||
#[allow(unused_must_use)]
|
||||
fn main() {
|
||||
let small = [1, 2];
|
||||
let big = [0u8; 33];
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
warning: this method call resolves to `<&[T; N] as IntoIterator>::into_iter` (due to backwards compatibility), but will resolve to <[T; N] as IntoIterator>::into_iter in Rust 2021
|
||||
--> $DIR/into-iter-on-arrays-lint.rs:10:11
|
||||
--> $DIR/into-iter-on-arrays-lint.rs:11:11
|
||||
|
|
||||
LL | small.into_iter();
|
||||
| ^^^^^^^^^
|
||||
|
@ -17,7 +17,7 @@ LL | IntoIterator::into_iter(small);
|
|||
| ++++++++++++++++++++++++ ~
|
||||
|
||||
warning: this method call resolves to `<&[T; N] as IntoIterator>::into_iter` (due to backwards compatibility), but will resolve to <[T; N] as IntoIterator>::into_iter in Rust 2021
|
||||
--> $DIR/into-iter-on-arrays-lint.rs:13:12
|
||||
--> $DIR/into-iter-on-arrays-lint.rs:14:12
|
||||
|
|
||||
LL | [1, 2].into_iter();
|
||||
| ^^^^^^^^^
|
||||
|
@ -34,7 +34,7 @@ LL | IntoIterator::into_iter([1, 2]);
|
|||
| ++++++++++++++++++++++++ ~
|
||||
|
||||
warning: this method call resolves to `<&[T; N] as IntoIterator>::into_iter` (due to backwards compatibility), but will resolve to <[T; N] as IntoIterator>::into_iter in Rust 2021
|
||||
--> $DIR/into-iter-on-arrays-lint.rs:16:9
|
||||
--> $DIR/into-iter-on-arrays-lint.rs:17:9
|
||||
|
|
||||
LL | big.into_iter();
|
||||
| ^^^^^^^^^
|
||||
|
@ -51,7 +51,7 @@ LL | IntoIterator::into_iter(big);
|
|||
| ++++++++++++++++++++++++ ~
|
||||
|
||||
warning: this method call resolves to `<&[T; N] as IntoIterator>::into_iter` (due to backwards compatibility), but will resolve to <[T; N] as IntoIterator>::into_iter in Rust 2021
|
||||
--> $DIR/into-iter-on-arrays-lint.rs:19:15
|
||||
--> $DIR/into-iter-on-arrays-lint.rs:20:15
|
||||
|
|
||||
LL | [0u8; 33].into_iter();
|
||||
| ^^^^^^^^^
|
||||
|
@ -68,7 +68,7 @@ LL | IntoIterator::into_iter([0u8; 33]);
|
|||
| ++++++++++++++++++++++++ ~
|
||||
|
||||
warning: this method call resolves to `<&[T; N] as IntoIterator>::into_iter` (due to backwards compatibility), but will resolve to <[T; N] as IntoIterator>::into_iter in Rust 2021
|
||||
--> $DIR/into-iter-on-arrays-lint.rs:23:21
|
||||
--> $DIR/into-iter-on-arrays-lint.rs:24:21
|
||||
|
|
||||
LL | Box::new(small).into_iter();
|
||||
| ^^^^^^^^^ help: use `.iter()` instead of `.into_iter()` to avoid ambiguity: `iter`
|
||||
|
@ -77,7 +77,7 @@ LL | Box::new(small).into_iter();
|
|||
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/IntoIterator-for-arrays.html>
|
||||
|
||||
warning: this method call resolves to `<&[T; N] as IntoIterator>::into_iter` (due to backwards compatibility), but will resolve to <[T; N] as IntoIterator>::into_iter in Rust 2021
|
||||
--> $DIR/into-iter-on-arrays-lint.rs:26:22
|
||||
--> $DIR/into-iter-on-arrays-lint.rs:27:22
|
||||
|
|
||||
LL | Box::new([1, 2]).into_iter();
|
||||
| ^^^^^^^^^ help: use `.iter()` instead of `.into_iter()` to avoid ambiguity: `iter`
|
||||
|
@ -86,7 +86,7 @@ LL | Box::new([1, 2]).into_iter();
|
|||
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/IntoIterator-for-arrays.html>
|
||||
|
||||
warning: this method call resolves to `<&[T; N] as IntoIterator>::into_iter` (due to backwards compatibility), but will resolve to <[T; N] as IntoIterator>::into_iter in Rust 2021
|
||||
--> $DIR/into-iter-on-arrays-lint.rs:29:19
|
||||
--> $DIR/into-iter-on-arrays-lint.rs:30:19
|
||||
|
|
||||
LL | Box::new(big).into_iter();
|
||||
| ^^^^^^^^^ help: use `.iter()` instead of `.into_iter()` to avoid ambiguity: `iter`
|
||||
|
@ -95,7 +95,7 @@ LL | Box::new(big).into_iter();
|
|||
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/IntoIterator-for-arrays.html>
|
||||
|
||||
warning: this method call resolves to `<&[T; N] as IntoIterator>::into_iter` (due to backwards compatibility), but will resolve to <[T; N] as IntoIterator>::into_iter in Rust 2021
|
||||
--> $DIR/into-iter-on-arrays-lint.rs:32:25
|
||||
--> $DIR/into-iter-on-arrays-lint.rs:33:25
|
||||
|
|
||||
LL | Box::new([0u8; 33]).into_iter();
|
||||
| ^^^^^^^^^ help: use `.iter()` instead of `.into_iter()` to avoid ambiguity: `iter`
|
||||
|
@ -104,7 +104,7 @@ LL | Box::new([0u8; 33]).into_iter();
|
|||
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/IntoIterator-for-arrays.html>
|
||||
|
||||
warning: this method call resolves to `<&[T; N] as IntoIterator>::into_iter` (due to backwards compatibility), but will resolve to <[T; N] as IntoIterator>::into_iter in Rust 2021
|
||||
--> $DIR/into-iter-on-arrays-lint.rs:36:31
|
||||
--> $DIR/into-iter-on-arrays-lint.rs:37:31
|
||||
|
|
||||
LL | Box::new(Box::new(small)).into_iter();
|
||||
| ^^^^^^^^^ help: use `.iter()` instead of `.into_iter()` to avoid ambiguity: `iter`
|
||||
|
@ -113,7 +113,7 @@ LL | Box::new(Box::new(small)).into_iter();
|
|||
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/IntoIterator-for-arrays.html>
|
||||
|
||||
warning: this method call resolves to `<&[T; N] as IntoIterator>::into_iter` (due to backwards compatibility), but will resolve to <[T; N] as IntoIterator>::into_iter in Rust 2021
|
||||
--> $DIR/into-iter-on-arrays-lint.rs:39:32
|
||||
--> $DIR/into-iter-on-arrays-lint.rs:40:32
|
||||
|
|
||||
LL | Box::new(Box::new([1, 2])).into_iter();
|
||||
| ^^^^^^^^^ help: use `.iter()` instead of `.into_iter()` to avoid ambiguity: `iter`
|
||||
|
@ -122,7 +122,7 @@ LL | Box::new(Box::new([1, 2])).into_iter();
|
|||
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/IntoIterator-for-arrays.html>
|
||||
|
||||
warning: this method call resolves to `<&[T; N] as IntoIterator>::into_iter` (due to backwards compatibility), but will resolve to <[T; N] as IntoIterator>::into_iter in Rust 2021
|
||||
--> $DIR/into-iter-on-arrays-lint.rs:42:29
|
||||
--> $DIR/into-iter-on-arrays-lint.rs:43:29
|
||||
|
|
||||
LL | Box::new(Box::new(big)).into_iter();
|
||||
| ^^^^^^^^^ help: use `.iter()` instead of `.into_iter()` to avoid ambiguity: `iter`
|
||||
|
@ -131,7 +131,7 @@ LL | Box::new(Box::new(big)).into_iter();
|
|||
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/IntoIterator-for-arrays.html>
|
||||
|
||||
warning: this method call resolves to `<&[T; N] as IntoIterator>::into_iter` (due to backwards compatibility), but will resolve to <[T; N] as IntoIterator>::into_iter in Rust 2021
|
||||
--> $DIR/into-iter-on-arrays-lint.rs:45:35
|
||||
--> $DIR/into-iter-on-arrays-lint.rs:46:35
|
||||
|
|
||||
LL | Box::new(Box::new([0u8; 33])).into_iter();
|
||||
| ^^^^^^^^^ help: use `.iter()` instead of `.into_iter()` to avoid ambiguity: `iter`
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
fn main() {
|
||||
let s = String::from("String");
|
||||
s.as_bytes().get(3);
|
||||
let _ = s.as_bytes().get(3);
|
||||
let _ = &s.as_bytes().get(3);
|
||||
s[..].as_bytes().get(3);
|
||||
let _ = s[..].as_bytes().get(3);
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
fn main() {
|
||||
let s = String::from("String");
|
||||
s.bytes().nth(3);
|
||||
let _ = s.bytes().nth(3);
|
||||
let _ = &s.bytes().nth(3);
|
||||
s[..].bytes().nth(3);
|
||||
let _ = s[..].bytes().nth(3);
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
error: called `.byte().nth()` on a `String`
|
||||
--> $DIR/bytes_nth.rs:8:5
|
||||
--> $DIR/bytes_nth.rs:8:13
|
||||
|
|
||||
LL | s.bytes().nth(3);
|
||||
| ^^^^^^^^^^^^^^^^ help: try: `s.as_bytes().get(3)`
|
||||
LL | let _ = s.bytes().nth(3);
|
||||
| ^^^^^^^^^^^^^^^^ help: try: `s.as_bytes().get(3)`
|
||||
|
|
||||
= note: `-D clippy::bytes-nth` implied by `-D warnings`
|
||||
|
||||
|
@ -13,10 +13,10 @@ LL | let _ = &s.bytes().nth(3);
|
|||
| ^^^^^^^^^^^^^^^^ help: try: `s.as_bytes().get(3)`
|
||||
|
||||
error: called `.byte().nth()` on a `str`
|
||||
--> $DIR/bytes_nth.rs:10:5
|
||||
--> $DIR/bytes_nth.rs:10:13
|
||||
|
|
||||
LL | s[..].bytes().nth(3);
|
||||
| ^^^^^^^^^^^^^^^^^^^^ help: try: `s[..].as_bytes().get(3)`
|
||||
LL | let _ = s[..].bytes().nth(3);
|
||||
| ^^^^^^^^^^^^^^^^^^^^ help: try: `s[..].as_bytes().get(3)`
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
|
|
@ -6,16 +6,16 @@ fn main() {
|
|||
let s = [1, 2, 3];
|
||||
let v = vec![1, 2, 3];
|
||||
|
||||
s.get(0);
|
||||
let _ = s.get(0);
|
||||
// Should be replaced by s.get(0)
|
||||
|
||||
s.get(2);
|
||||
let _ = s.get(2);
|
||||
// Should be replaced by s.get(2)
|
||||
|
||||
v.get(5);
|
||||
let _ = v.get(5);
|
||||
// Should be replaced by v.get(5)
|
||||
|
||||
v.get(0);
|
||||
let _ = v.get(0);
|
||||
// Should be replaced by v.get(0)
|
||||
|
||||
let o = Some(5);
|
||||
|
|
|
@ -6,16 +6,16 @@ fn main() {
|
|||
let s = [1, 2, 3];
|
||||
let v = vec![1, 2, 3];
|
||||
|
||||
s.iter().next();
|
||||
let _ = s.iter().next();
|
||||
// Should be replaced by s.get(0)
|
||||
|
||||
s[2..].iter().next();
|
||||
let _ = s[2..].iter().next();
|
||||
// Should be replaced by s.get(2)
|
||||
|
||||
v[5..].iter().next();
|
||||
let _ = v[5..].iter().next();
|
||||
// Should be replaced by v.get(5)
|
||||
|
||||
v.iter().next();
|
||||
let _ = v.iter().next();
|
||||
// Should be replaced by v.get(0)
|
||||
|
||||
let o = Some(5);
|
||||
|
|
|
@ -1,28 +1,28 @@
|
|||
error: using `.iter().next()` on an array
|
||||
--> $DIR/iter_next_slice.rs:9:5
|
||||
--> $DIR/iter_next_slice.rs:9:13
|
||||
|
|
||||
LL | s.iter().next();
|
||||
| ^^^^^^^^^^^^^^^ help: try calling: `s.get(0)`
|
||||
LL | let _ = s.iter().next();
|
||||
| ^^^^^^^^^^^^^^^ help: try calling: `s.get(0)`
|
||||
|
|
||||
= note: `-D clippy::iter-next-slice` implied by `-D warnings`
|
||||
|
||||
error: using `.iter().next()` on a Slice without end index
|
||||
--> $DIR/iter_next_slice.rs:12:5
|
||||
--> $DIR/iter_next_slice.rs:12:13
|
||||
|
|
||||
LL | s[2..].iter().next();
|
||||
| ^^^^^^^^^^^^^^^^^^^^ help: try calling: `s.get(2)`
|
||||
LL | let _ = s[2..].iter().next();
|
||||
| ^^^^^^^^^^^^^^^^^^^^ help: try calling: `s.get(2)`
|
||||
|
||||
error: using `.iter().next()` on a Slice without end index
|
||||
--> $DIR/iter_next_slice.rs:15:5
|
||||
--> $DIR/iter_next_slice.rs:15:13
|
||||
|
|
||||
LL | v[5..].iter().next();
|
||||
| ^^^^^^^^^^^^^^^^^^^^ help: try calling: `v.get(5)`
|
||||
LL | let _ = v[5..].iter().next();
|
||||
| ^^^^^^^^^^^^^^^^^^^^ help: try calling: `v.get(5)`
|
||||
|
||||
error: using `.iter().next()` on an array
|
||||
--> $DIR/iter_next_slice.rs:18:5
|
||||
--> $DIR/iter_next_slice.rs:18:13
|
||||
|
|
||||
LL | v.iter().next();
|
||||
| ^^^^^^^^^^^^^^^ help: try calling: `v.get(0)`
|
||||
LL | let _ = v.iter().next();
|
||||
| ^^^^^^^^^^^^^^^ help: try calling: `v.get(0)`
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue