From 86e8edea6b2ed2059fbed2c1d7c6dd18ca525f98 Mon Sep 17 00:00:00 2001 From: Nathan Perry Date: Wed, 31 Jul 2024 08:23:50 -0400 Subject: [PATCH] liballoc/{String,Vec}: fixup const attributes, some old fn names --- library/alloc/src/lib.rs | 1 + library/alloc/src/string.rs | 16 ++++++++-------- library/alloc/src/vec/mod.rs | 12 ++++++------ 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs index 6c58594605004..ca392357e310f 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -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)] diff --git a/library/alloc/src/string.rs b/library/alloc/src/string.rs index 2edd3e48d4296..593a2fadb2448 100644 --- a/library/alloc/src/string.rs +++ b/library/alloc/src/string.rs @@ -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 { self.vec } @@ -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. @@ -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() } @@ -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. @@ -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() @@ -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 } diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 644eb49b424e4..1d69eba16379e 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -944,7 +944,7 @@ impl Vec { /// ``` #[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() } @@ -1252,9 +1252,9 @@ impl Vec { /// ``` #[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. @@ -1326,7 +1326,7 @@ impl Vec { /// [`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 { @@ -2263,7 +2263,7 @@ impl Vec { /// ``` #[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 @@ -2281,7 +2281,7 @@ impl Vec { /// 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 }