Skip to content

Commit

Permalink
liballoc/{String,Vec}: fixup const attributes, some old fn names
Browse files Browse the repository at this point in the history
  • Loading branch information
mammothbane committed Jul 31, 2024
1 parent f1a74be commit 86e8ede
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
1 change: 1 addition & 0 deletions library/alloc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
#![feature(const_pin)]
#![feature(const_refs_to_cell)]
#![feature(const_size_of_val)]
#![feature(const_vec_string_slice)]
#![feature(core_intrinsics)]
#![feature(deprecated_suggestion)]
#![feature(deref_pure_trait)]
Expand Down
16 changes: 8 additions & 8 deletions library/alloc/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,7 @@ impl String {
#[inline]
#[must_use = "`self` will be dropped if the result is not used"]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_vec_string_slice")]
#[rustc_const_unstable(feature = "const_vec_string_slice", issue = "none")]
pub const fn into_bytes(self) -> Vec<u8> {
self.vec
}
Expand All @@ -1023,9 +1023,9 @@ impl String {
#[inline]
#[must_use]
#[stable(feature = "string_as_str", since = "1.7.0")]
#[rustc_const_unstable(feature = "const_vec_string_slice")]
#[rustc_const_unstable(feature = "const_vec_string_slice", issue = "none")]
pub const fn as_str(&self) -> &str {
unsafe { str::from_utf8_unchecked(self.vec.as_slice_const()) }
unsafe { str::from_utf8_unchecked(self.vec.as_slice()) }
}

/// Converts a `String` into a mutable string slice.
Expand Down Expand Up @@ -1114,7 +1114,7 @@ impl String {
#[inline]
#[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_vec_string_slice")]
#[rustc_const_unstable(feature = "const_vec_string_slice", issue = "none")]
pub const fn capacity(&self) -> usize {
self.vec.capacity()
}
Expand Down Expand Up @@ -1378,9 +1378,9 @@ impl String {
#[inline]
#[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_vec_string_slice")]
#[rustc_const_unstable(feature = "const_vec_string_slice", issue = "none")]
pub const fn as_bytes(&self) -> &[u8] {
&self.vec
self.vec.as_slice()
}

/// Shortens this `String` to the specified length.
Expand Down Expand Up @@ -1752,7 +1752,7 @@ impl String {
#[inline]
#[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_vec_string_slice")]
#[rustc_const_unstable(feature = "const_vec_string_slice", issue = "none")]
#[rustc_confusables("length", "size")]
pub const fn len(&self) -> usize {
self.vec.len()
Expand All @@ -1772,7 +1772,7 @@ impl String {
#[inline]
#[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_vec_string_slice")]
#[rustc_const_unstable(feature = "const_vec_string_slice", issue = "none")]
pub const fn is_empty(&self) -> bool {
self.len() == 0
}
Expand Down
12 changes: 6 additions & 6 deletions library/alloc/src/vec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,7 @@ impl<T, A: Allocator> Vec<T, A> {
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_vec_string_slice")]
#[rustc_const_unstable(feature = "const_vec_string_slice", issue = "none")]
pub const fn capacity(&self) -> usize {
self.buf.capacity()
}
Expand Down Expand Up @@ -1252,9 +1252,9 @@ impl<T, A: Allocator> Vec<T, A> {
/// ```
#[inline]
#[stable(feature = "vec_as_slice", since = "1.7.0")]
#[rustc_const_unstable(feature = "const_vec_string_slice")]
#[rustc_const_unstable(feature = "const_vec_string_slice", issue = "none")]
pub const fn as_slice(&self) -> &[T] {
unsafe { slice::from_raw_parts(self.as_ptr_const(), self.len) }
unsafe { slice::from_raw_parts(self.as_ptr(), self.len) }
}

/// Extracts a mutable slice of the entire vector.
Expand Down Expand Up @@ -1326,7 +1326,7 @@ impl<T, A: Allocator> Vec<T, A> {
/// [`as_mut_ptr`]: Vec::as_mut_ptr
/// [`as_ptr`]: Vec::as_ptr
#[stable(feature = "vec_as_ptr", since = "1.37.0")]
#[rustc_const_unstable(feature = "const_vec_string_slice")]
#[rustc_const_unstable(feature = "const_vec_string_slice", issue = "none")]
#[rustc_never_returns_null_ptr]
#[inline]
pub const fn as_ptr(&self) -> *const T {
Expand Down Expand Up @@ -2263,7 +2263,7 @@ impl<T, A: Allocator> Vec<T, A> {
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_vec_string_slice")]
#[rustc_const_unstable(feature = "const_vec_string_slice", issue = "none")]
#[rustc_confusables("length", "size")]
pub const fn len(&self) -> usize {
self.len
Expand All @@ -2281,7 +2281,7 @@ impl<T, A: Allocator> Vec<T, A> {
/// assert!(!v.is_empty());
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_vec_string_slice")]
#[rustc_const_unstable(feature = "const_vec_string_slice", issue = "none")]
pub const fn is_empty(&self) -> bool {
self.len() == 0
}
Expand Down

0 comments on commit 86e8ede

Please sign in to comment.