Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stabilize const_vec_string_slice #137319

Merged
merged 1 commit into from
Mar 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions library/alloc/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,8 @@ 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", issue = "129041")]
#[rustc_const_stable(feature = "const_vec_string_slice", since = "CURRENT_RUSTC_VERSION")]
#[rustc_allow_const_fn_unstable(const_precise_live_drops)]
pub const fn into_bytes(self) -> Vec<u8> {
self.vec
}
Expand All @@ -1061,7 +1062,7 @@ impl String {
#[must_use]
#[stable(feature = "string_as_str", since = "1.7.0")]
#[rustc_diagnostic_item = "string_as_str"]
#[rustc_const_unstable(feature = "const_vec_string_slice", issue = "129041")]
#[rustc_const_stable(feature = "const_vec_string_slice", since = "CURRENT_RUSTC_VERSION")]
pub const fn as_str(&self) -> &str {
// SAFETY: String contents are stipulated to be valid UTF-8, invalid contents are an error
// at construction.
Expand All @@ -1084,7 +1085,7 @@ impl String {
#[must_use]
#[stable(feature = "string_as_str", since = "1.7.0")]
#[rustc_diagnostic_item = "string_as_mut_str"]
#[rustc_const_unstable(feature = "const_vec_string_slice", issue = "129041")]
#[rustc_const_stable(feature = "const_vec_string_slice", since = "CURRENT_RUSTC_VERSION")]
pub const fn as_mut_str(&mut self) -> &mut str {
// SAFETY: String contents are stipulated to be valid UTF-8, invalid contents are an error
// at construction.
Expand Down Expand Up @@ -1158,7 +1159,7 @@ impl String {
#[inline]
#[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_vec_string_slice", issue = "129041")]
#[rustc_const_stable(feature = "const_vec_string_slice", since = "CURRENT_RUSTC_VERSION")]
pub const fn capacity(&self) -> usize {
self.vec.capacity()
}
Expand Down Expand Up @@ -1424,7 +1425,7 @@ impl String {
#[inline]
#[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_vec_string_slice", issue = "129041")]
#[rustc_const_stable(feature = "const_vec_string_slice", since = "CURRENT_RUSTC_VERSION")]
pub const fn as_bytes(&self) -> &[u8] {
self.vec.as_slice()
}
Expand Down Expand Up @@ -1778,7 +1779,7 @@ impl String {
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_vec_string_slice", issue = "129041")]
#[rustc_const_stable(feature = "const_vec_string_slice", since = "CURRENT_RUSTC_VERSION")]
pub const unsafe fn as_mut_vec(&mut self) -> &mut Vec<u8> {
&mut self.vec
}
Expand All @@ -1800,7 +1801,7 @@ impl String {
#[inline]
#[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_vec_string_slice", issue = "129041")]
#[rustc_const_stable(feature = "const_vec_string_slice", since = "CURRENT_RUSTC_VERSION")]
#[rustc_confusables("length", "size")]
pub const fn len(&self) -> usize {
self.vec.len()
Expand All @@ -1820,7 +1821,7 @@ impl String {
#[inline]
#[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_vec_string_slice", issue = "129041")]
#[rustc_const_stable(feature = "const_vec_string_slice", since = "CURRENT_RUSTC_VERSION")]
pub const fn is_empty(&self) -> bool {
self.len() == 0
}
Expand Down
14 changes: 7 additions & 7 deletions library/alloc/src/vec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1254,7 +1254,7 @@ impl<T, A: Allocator> Vec<T, A> {
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_vec_string_slice", issue = "129041")]
#[rustc_const_stable(feature = "const_vec_string_slice", since = "CURRENT_RUSTC_VERSION")]
pub const fn capacity(&self) -> usize {
self.buf.capacity()
}
Expand Down Expand Up @@ -1569,7 +1569,7 @@ impl<T, A: Allocator> Vec<T, A> {
#[inline]
#[stable(feature = "vec_as_slice", since = "1.7.0")]
#[rustc_diagnostic_item = "vec_as_slice"]
#[rustc_const_unstable(feature = "const_vec_string_slice", issue = "129041")]
#[rustc_const_stable(feature = "const_vec_string_slice", since = "CURRENT_RUSTC_VERSION")]
pub const fn as_slice(&self) -> &[T] {
// SAFETY: `slice::from_raw_parts` requires pointee is a contiguous, aligned buffer of size
// `len` containing properly-initialized `T`s. Data must not be mutated for the returned
Expand Down Expand Up @@ -1601,7 +1601,7 @@ impl<T, A: Allocator> Vec<T, A> {
#[inline]
#[stable(feature = "vec_as_slice", since = "1.7.0")]
#[rustc_diagnostic_item = "vec_as_mut_slice"]
#[rustc_const_unstable(feature = "const_vec_string_slice", issue = "129041")]
#[rustc_const_stable(feature = "const_vec_string_slice", since = "CURRENT_RUSTC_VERSION")]
pub const fn as_mut_slice(&mut self) -> &mut [T] {
// SAFETY: `slice::from_raw_parts_mut` requires pointee is a contiguous, aligned buffer of
// size `len` containing properly-initialized `T`s. Data must not be accessed through any
Expand Down Expand Up @@ -1673,7 +1673,7 @@ impl<T, A: Allocator> Vec<T, A> {
/// [`as_ptr`]: Vec::as_ptr
/// [`as_non_null`]: Vec::as_non_null
#[stable(feature = "vec_as_ptr", since = "1.37.0")]
#[rustc_const_unstable(feature = "const_vec_string_slice", issue = "129041")]
#[rustc_const_stable(feature = "const_vec_string_slice", since = "CURRENT_RUSTC_VERSION")]
#[rustc_never_returns_null_ptr]
#[rustc_as_ptr]
#[inline]
Expand Down Expand Up @@ -1736,7 +1736,7 @@ impl<T, A: Allocator> Vec<T, A> {
/// [`as_ptr`]: Vec::as_ptr
/// [`as_non_null`]: Vec::as_non_null
#[stable(feature = "vec_as_ptr", since = "1.37.0")]
#[rustc_const_unstable(feature = "const_vec_string_slice", issue = "129041")]
#[rustc_const_stable(feature = "const_vec_string_slice", since = "CURRENT_RUSTC_VERSION")]
#[rustc_never_returns_null_ptr]
#[rustc_as_ptr]
#[inline]
Expand Down Expand Up @@ -2687,7 +2687,7 @@ impl<T, A: Allocator> Vec<T, A> {
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_vec_string_slice", issue = "129041")]
#[rustc_const_stable(feature = "const_vec_string_slice", since = "CURRENT_RUSTC_VERSION")]
#[rustc_confusables("length", "size")]
pub const fn len(&self) -> usize {
let len = self.len;
Expand All @@ -2713,7 +2713,7 @@ impl<T, A: Allocator> Vec<T, A> {
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_diagnostic_item = "vec_is_empty"]
#[rustc_const_unstable(feature = "const_vec_string_slice", issue = "129041")]
#[rustc_const_stable(feature = "const_vec_string_slice", since = "CURRENT_RUSTC_VERSION")]
pub const fn is_empty(&self) -> bool {
self.len() == 0
}
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/consts/issue-94675.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(const_trait_impl, const_vec_string_slice)]
#![feature(const_trait_impl)]

struct Foo<'a> {
bar: &'a mut Vec<usize>,
Expand Down
Loading