Rollup merge of #84094 - tmiasko:remove-fixed-size-array, r=m-ou-se

Remove FixedSizeArray

Remove `FixedSizeArray` trait, it has been superseded by const generics.

Closes #27778.
This commit is contained in:
Dylan DPC 2021-04-12 01:04:09 +02:00 committed by GitHub
commit 3ea5a9f301
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 1 additions and 57 deletions

View file

@ -12,7 +12,6 @@ use crate::convert::{Infallible, TryFrom};
use crate::fmt; use crate::fmt;
use crate::hash::{self, Hash}; use crate::hash::{self, Hash};
use crate::iter::TrustedLen; use crate::iter::TrustedLen;
use crate::marker::Unsize;
use crate::mem::{self, MaybeUninit}; use crate::mem::{self, MaybeUninit};
use crate::ops::{Index, IndexMut}; use crate::ops::{Index, IndexMut};
use crate::slice::{Iter, IterMut}; use crate::slice::{Iter, IterMut};
@ -36,41 +35,6 @@ pub fn from_mut<T>(s: &mut T) -> &mut [T; 1] {
unsafe { &mut *(s as *mut T).cast::<[T; 1]>() } unsafe { &mut *(s as *mut T).cast::<[T; 1]>() }
} }
/// Utility trait implemented only on arrays of fixed size
///
/// This trait can be used to implement other traits on fixed-size arrays
/// without causing much metadata bloat.
///
/// The trait is marked unsafe in order to restrict implementors to fixed-size
/// arrays. A user of this trait can assume that implementors have the exact
/// layout in memory of a fixed size array (for example, for unsafe
/// initialization).
///
/// Note that the traits [`AsRef`] and [`AsMut`] provide similar methods for types that
/// may not be fixed-size arrays. Implementors should prefer those traits
/// instead.
#[unstable(feature = "fixed_size_array", issue = "27778")]
pub unsafe trait FixedSizeArray<T> {
/// Converts the array to immutable slice
#[unstable(feature = "fixed_size_array", issue = "27778")]
fn as_slice(&self) -> &[T];
/// Converts the array to mutable slice
#[unstable(feature = "fixed_size_array", issue = "27778")]
fn as_mut_slice(&mut self) -> &mut [T];
}
#[unstable(feature = "fixed_size_array", issue = "27778")]
unsafe impl<T, A: Unsize<[T]>> FixedSizeArray<T> for A {
#[inline]
fn as_slice(&self) -> &[T] {
self
}
#[inline]
fn as_mut_slice(&mut self) -> &mut [T] {
self
}
}
/// The error type returned when a conversion from a slice to an array fails. /// The error type returned when a conversion from a slice to an array fails.
#[stable(feature = "try_from", since = "1.34.0")] #[stable(feature = "try_from", since = "1.34.0")]
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]

View file

@ -1,24 +1,6 @@
use core::array::{self, FixedSizeArray, IntoIter}; use core::array::{self, IntoIter};
use core::convert::TryFrom; use core::convert::TryFrom;
#[test]
fn fixed_size_array() {
let mut array = [0; 64];
let mut zero_sized = [(); 64];
let mut empty_array = [0; 0];
let mut empty_zero_sized = [(); 0];
assert_eq!(FixedSizeArray::as_slice(&array).len(), 64);
assert_eq!(FixedSizeArray::as_slice(&zero_sized).len(), 64);
assert_eq!(FixedSizeArray::as_slice(&empty_array).len(), 0);
assert_eq!(FixedSizeArray::as_slice(&empty_zero_sized).len(), 0);
assert_eq!(FixedSizeArray::as_mut_slice(&mut array).len(), 64);
assert_eq!(FixedSizeArray::as_mut_slice(&mut zero_sized).len(), 64);
assert_eq!(FixedSizeArray::as_mut_slice(&mut empty_array).len(), 0);
assert_eq!(FixedSizeArray::as_mut_slice(&mut empty_zero_sized).len(), 0);
}
#[test] #[test]
fn array_from_ref() { fn array_from_ref() {
let value: String = "Hello World!".into(); let value: String = "Hello World!".into();

View file

@ -28,7 +28,6 @@
#![feature(duration_zero)] #![feature(duration_zero)]
#![feature(exact_size_is_empty)] #![feature(exact_size_is_empty)]
#![feature(extern_types)] #![feature(extern_types)]
#![feature(fixed_size_array)]
#![feature(flt2dec)] #![feature(flt2dec)]
#![feature(fmt_internals)] #![feature(fmt_internals)]
#![feature(hashmap_internals)] #![feature(hashmap_internals)]

View file

@ -214,7 +214,6 @@
feature(slice_index_methods, coerce_unsized, sgx_platform) feature(slice_index_methods, coerce_unsized, sgx_platform)
)] )]
#![deny(rustc::existing_doc_keyword)] #![deny(rustc::existing_doc_keyword)]
#![cfg_attr(all(test, target_vendor = "fortanix", target_env = "sgx"), feature(fixed_size_array))]
// std is implemented with unstable features, many of which are internal // std is implemented with unstable features, many of which are internal
// compiler details that will never be stable // compiler details that will never be stable
// NB: the following list is sorted to minimize merge conflicts. // NB: the following list is sorted to minimize merge conflicts.