Rollup merge of #128399 - mammothbane:master, r=Amanieu,tgross35 · qinheping/verify-rust-std@6a809c7 (original) (raw)
`@@ -1240,7 +1240,8 @@ impl<T, A: Allocator> Vec<T, A> {
`
1240
1240
```` /// ```
`1241`
`1241`
`#[inline]
`
`1242`
`1242`
`#[stable(feature = "rust1", since = "1.0.0")]
`
`1243`
``
`-
pub fn capacity(&self) -> usize {
`
``
`1243`
`+
#[rustc_const_unstable(feature = "const_vec_string_slice", issue = "129041")]
`
``
`1244`
`+
pub const fn capacity(&self) -> usize {
`
`1244`
`1245`
`self.buf.capacity()
`
`1245`
`1246`
`}
`
`1246`
`1247`
``
`@@ -1548,8 +1549,22 @@ impl<T, A: Allocator> Vec<T, A> {
`
`1548`
`1549`
`#[inline]
`
`1549`
`1550`
`#[stable(feature = "vec_as_slice", since = "1.7.0")]
`
`1550`
`1551`
`#[cfg_attr(not(test), rustc_diagnostic_item = "vec_as_slice")]
`
`1551`
``
`-
pub fn as_slice(&self) -> &[T] {
`
`1552`
``
`-
self
`
``
`1552`
`+
#[rustc_const_unstable(feature = "const_vec_string_slice", issue = "129041")]
`
``
`1553`
`+
pub const fn as_slice(&self) -> &[T] {
`
``
`1554`
`` +
// SAFETY: `slice::from_raw_parts` requires pointee is a contiguous, aligned buffer of size
``
``
`1555`
`` +
// `len` containing properly-initialized `T`s. Data must not be mutated for the returned
``
``
`1556`
`` +
// lifetime. Further, `len * mem::size_of::<T>` <= `ISIZE::MAX`, and allocation does not
``
``
`1557`
`+
// "wrap" through overflowing memory addresses.
`
``
`1558`
`+
//
`
``
`1559`
`+
// * Vec API guarantees that self.buf:
`
``
`1560`
`+
// * contains only properly-initialized items within 0..len
`
``
`1561`
`` +
// * is aligned, contiguous, and valid for `len` reads
``
``
`1562`
`+
// * obeys size and address-wrapping constraints
`
``
`1563`
`+
//
`
``
`1564`
`` +
// * We only construct `&mut` references to `self.buf` through `&mut self` methods; borrow-
``
``
`1565`
`` +
// check ensures that it is not possible to mutably alias `self.buf` within the
``
``
`1566`
`+
// returned lifetime.
`
``
`1567`
`+
unsafe { slice::from_raw_parts(self.as_ptr(), self.len) }
`
`1553`
`1568`
`}
`
`1554`
`1569`
``
`1555`
`1570`
`/// Extracts a mutable slice of the entire vector.
`
`@@ -1566,8 +1581,22 @@ impl<T, A: Allocator> Vec<T, A> {
`
`1566`
`1581`
`#[inline]
`
`1567`
`1582`
`#[stable(feature = "vec_as_slice", since = "1.7.0")]
`
`1568`
`1583`
`#[cfg_attr(not(test), rustc_diagnostic_item = "vec_as_mut_slice")]
`
`1569`
``
`-
pub fn as_mut_slice(&mut self) -> &mut [T] {
`
`1570`
``
`-
self
`
``
`1584`
`+
#[rustc_const_unstable(feature = "const_vec_string_slice", issue = "129041")]
`
``
`1585`
`+
pub const fn as_mut_slice(&mut self) -> &mut [T] {
`
``
`1586`
`` +
// SAFETY: `slice::from_raw_parts_mut` requires pointee is a contiguous, aligned buffer of
``
``
`1587`
`` +
// size `len` containing properly-initialized `T`s. Data must not be accessed through any
``
``
`1588`
`` +
// other pointer for the returned lifetime. Further, `len * mem::size_of::<T>` <=
``
``
`1589`
`` +
// `ISIZE::MAX` and allocation does not "wrap" through overflowing memory addresses.
``
``
`1590`
`+
//
`
``
`1591`
`+
// * Vec API guarantees that self.buf:
`
``
`1592`
`+
// * contains only properly-initialized items within 0..len
`
``
`1593`
`` +
// * is aligned, contiguous, and valid for `len` reads
``
``
`1594`
`+
// * obeys size and address-wrapping constraints
`
``
`1595`
`+
//
`
``
`1596`
`` +
// * We only construct references to `self.buf` through `&self` and `&mut self` methods;
``
``
`1597`
`` +
// borrow-check ensures that it is not possible to construct a reference to `self.buf`
``
``
`1598`
`+
// within the returned lifetime.
`
``
`1599`
`+
unsafe { slice::from_raw_parts_mut(self.as_mut_ptr(), self.len) }
`
`1571`
`1600`
`}
`
`1572`
`1601`
``
`1573`
`1602`
`/// Returns a raw pointer to the vector's buffer, or a dangling raw pointer
`
`@@ -1624,9 +1653,10 @@ impl<T, A: Allocator> Vec<T, A> {
`
`1624`
`1653`
`` /// [`as_ptr`]: Vec::as_ptr
``
`1625`
`1654`
`` /// [`as_non_null`]: Vec::as_non_null
``
`1626`
`1655`
`#[stable(feature = "vec_as_ptr", since = "1.37.0")]
`
``
`1656`
`+
#[rustc_const_unstable(feature = "const_vec_string_slice", issue = "129041")]
`
`1627`
`1657`
`#[rustc_never_returns_null_ptr]
`
`1628`
`1658`
`#[inline]
`
`1629`
``
`-
pub fn as_ptr(&self) -> *const T {
`
``
`1659`
`+
pub const fn as_ptr(&self) -> *const T {
`
`1630`
`1660`
`// We shadow the slice method of the same name to avoid going through
`
`1631`
`1661`
`` // `deref`, which creates an intermediate reference.
``
`1632`
`1662`
`self.buf.ptr()
`
`@@ -1685,9 +1715,10 @@ impl<T, A: Allocator> Vec<T, A> {
`
`1685`
`1715`
`` /// [`as_ptr`]: Vec::as_ptr
``
`1686`
`1716`
`` /// [`as_non_null`]: Vec::as_non_null
``
`1687`
`1717`
`#[stable(feature = "vec_as_ptr", since = "1.37.0")]
`
``
`1718`
`+
#[rustc_const_unstable(feature = "const_vec_string_slice", issue = "129041")]
`
`1688`
`1719`
`#[rustc_never_returns_null_ptr]
`
`1689`
`1720`
`#[inline]
`
`1690`
``
`-
pub fn as_mut_ptr(&mut self) -> *mut T {
`
``
`1721`
`+
pub const fn as_mut_ptr(&mut self) -> *mut T {
`
`1691`
`1722`
`// We shadow the slice method of the same name to avoid going through
`
`1692`
`1723`
`` // `deref_mut`, which creates an intermediate reference.
``
`1693`
`1724`
`self.buf.ptr()
`
`@@ -2628,8 +2659,9 @@ impl<T, A: Allocator> Vec<T, A> {
`
`2628`
`2659`
```` /// ```
2629
2660
`#[inline]
`
2630
2661
`#[stable(feature = "rust1", since = "1.0.0")]
`
``
2662
`+
#[rustc_const_unstable(feature = "const_vec_string_slice", issue = "129041")]
`
2631
2663
`#[rustc_confusables("length", "size")]
`
2632
``
`-
pub fn len(&self) -> usize {
`
``
2664
`+
pub const fn len(&self) -> usize {
`
2633
2665
`self.len
`
2634
2666
`}
`
2635
2667
``
`@@ -2646,7 +2678,8 @@ impl<T, A: Allocator> Vec<T, A> {
`
2646
2678
```` /// ```
````
2647
2679
`#[stable(feature = "rust1", since = "1.0.0")]
`
2648
2680
`#[cfg_attr(not(test), rustc_diagnostic_item = "vec_is_empty")]
`
2649
``
`-
pub fn is_empty(&self) -> bool {
`
``
2681
`+
#[rustc_const_unstable(feature = "const_vec_string_slice", issue = "129041")]
`
``
2682
`+
pub const fn is_empty(&self) -> bool {
`
2650
2683
`self.len() == 0
`
2651
2684
`}
`
2652
2685
``
`@@ -3197,15 +3230,15 @@ impl<T, A: Allocator> ops::Deref for Vec<T, A> {
`
3197
3230
``
3198
3231
`#[inline]
`
3199
3232
`fn deref(&self) -> &[T] {
`
3200
``
`-
unsafe { slice::from_raw_parts(self.as_ptr(), self.len) }
`
``
3233
`+
self.as_slice()
`
3201
3234
`}
`
3202
3235
`}
`
3203
3236
``
3204
3237
`#[stable(feature = "rust1", since = "1.0.0")]
`
3205
3238
`impl<T, A: Allocator> ops::DerefMut for Vec<T, A> {
`
3206
3239
`#[inline]
`
3207
3240
`fn deref_mut(&mut self) -> &mut [T] {
`
3208
``
`-
unsafe { slice::from_raw_parts_mut(self.as_mut_ptr(), self.len) }
`
``
3241
`+
self.as_mut_slice()
`
3209
3242
`}
`
3210
3243
`}
`
3211
3244
``