diff options
| author | bors <bors@rust-lang.org> | 2020-11-16 22:32:40 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2020-11-16 22:32:40 +0000 |
| commit | c6a6105bccd5599daf0ecef40c4b5ffa175fc1c1 (patch) | |
| tree | 4f3c7a87cf0dadf0ddc4485c9d823ac351058844 /library/core/src/array | |
| parent | f5230fbf76bafd86ee4376a0e26e551df8d17fec (diff) | |
| parent | e6b6c8e4fc63b2229e4db079510c1dac26917437 (diff) | |
| download | rust-c6a6105bccd5599daf0ecef40c4b5ffa175fc1c1.tar.gz rust-c6a6105bccd5599daf0ecef40c4b5ffa175fc1c1.zip | |
Auto merge of #79104 - m-ou-se:rollup-v74492y, r=m-ou-se
Rollup of 11 pull requests Successful merges: - #74989 (Implement `Index` and `IndexMut` for arrays) - #76339 (Test structural matching for all range types) - #77691 (Rename/Deprecate LayoutErr in favor of LayoutError) - #78364 (Update RELEASES.md for 1.48.0) - #78678 (Add tests and improve rendering of cfgs on traits) - #78714 (Simplify output capturing) - #78769 (Remove unneeded lifetimes in array/mod.rs) - #78903 (BTreeMap: test chaotic ordering & other bits & bobs) - #79032 (improve type const mismatch errors) - #79061 (Make all rustdoc functions and structs crate-private) - #79087 (Update E0744 about control flow in `const` contexts to accurately describe when the error is triggered and why) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'library/core/src/array')
| -rw-r--r-- | library/core/src/array/mod.rs | 41 |
1 files changed, 33 insertions, 8 deletions
diff --git a/library/core/src/array/mod.rs b/library/core/src/array/mod.rs index 123a191dd2c..a7cb1023229 100644 --- a/library/core/src/array/mod.rs +++ b/library/core/src/array/mod.rs @@ -12,6 +12,7 @@ use crate::convert::{Infallible, TryFrom}; use crate::fmt; use crate::hash::{self, Hash}; use crate::marker::Unsize; +use crate::ops::{Index, IndexMut}; use crate::slice::{Iter, IterMut}; mod iter; @@ -208,6 +209,30 @@ impl<'a, T, const N: usize> IntoIterator for &'a mut [T; N] { } } +#[stable(feature = "index_trait_on_arrays", since = "1.50.0")] +impl<T, I, const N: usize> Index<I> for [T; N] +where + [T]: Index<I>, +{ + type Output = <[T] as Index<I>>::Output; + + #[inline] + fn index(&self, index: I) -> &Self::Output { + Index::index(self as &[T], index) + } +} + +#[stable(feature = "index_trait_on_arrays", since = "1.50.0")] +impl<T, I, const N: usize> IndexMut<I> for [T; N] +where + [T]: IndexMut<I>, +{ + #[inline] + fn index_mut(&mut self, index: I) -> &mut Self::Output { + IndexMut::index_mut(self as &mut [T], index) + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl<A, B, const N: usize> PartialEq<[B; N]> for [A; N] where @@ -254,22 +279,22 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl<'b, A, B, const N: usize> PartialEq<&'b [B]> for [A; N] +impl<A, B, const N: usize> PartialEq<&[B]> for [A; N] where A: PartialEq<B>, { #[inline] - fn eq(&self, other: &&'b [B]) -> bool { + fn eq(&self, other: &&[B]) -> bool { self[..] == other[..] } #[inline] - fn ne(&self, other: &&'b [B]) -> bool { + fn ne(&self, other: &&[B]) -> bool { self[..] != other[..] } } #[stable(feature = "rust1", since = "1.0.0")] -impl<'b, A, B, const N: usize> PartialEq<[A; N]> for &'b [B] +impl<A, B, const N: usize> PartialEq<[A; N]> for &[B] where B: PartialEq<A>, { @@ -284,22 +309,22 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl<'b, A, B, const N: usize> PartialEq<&'b mut [B]> for [A; N] +impl<A, B, const N: usize> PartialEq<&mut [B]> for [A; N] where A: PartialEq<B>, { #[inline] - fn eq(&self, other: &&'b mut [B]) -> bool { + fn eq(&self, other: &&mut [B]) -> bool { self[..] == other[..] } #[inline] - fn ne(&self, other: &&'b mut [B]) -> bool { + fn ne(&self, other: &&mut [B]) -> bool { self[..] != other[..] } } #[stable(feature = "rust1", since = "1.0.0")] -impl<'b, A, B, const N: usize> PartialEq<[A; N]> for &'b mut [B] +impl<A, B, const N: usize> PartialEq<[A; N]> for &mut [B] where B: PartialEq<A>, { |
