about summary refs log tree commit diff
path: root/library/alloc/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2025-07-08 14:04:40 +0000
committerbors <bors@rust-lang.org>2025-07-08 14:04:40 +0000
commitf838cbc06de60819faff3413f374706b74824ca2 (patch)
treea4cff09f57a030086065792de4df4ba27c887af8 /library/alloc/src
parent040e2f8b9ff2d76fbe2146d6003e297ed4532088 (diff)
parent8f8099fb42f0b067cd9b6a82e704ce3cc0e63301 (diff)
downloadrust-f838cbc06de60819faff3413f374706b74824ca2.tar.gz
rust-f838cbc06de60819faff3413f374706b74824ca2.zip
Auto merge of #134628 - estebank:const-default, r=oli-obk
Make `Default` const and add some `const Default` impls

Full list of `impl const Default` types:

- ()
- bool
- char
- std::ascii::Char
- usize
- u8
- u16
- u32
- u64
- u128
- i8
- i16
- i32
- i64
- i128
- f16
- f32
- f64
- f128
- std::marker::PhantomData<T>
- Option<T>
- std::iter::Empty<T>
- std::ptr::Alignment
- &[T]
- &mut [T]
- &str
- &mut str
- String
- Vec<T>
Diffstat (limited to 'library/alloc/src')
-rw-r--r--library/alloc/src/lib.rs2
-rw-r--r--library/alloc/src/string.rs3
-rw-r--r--library/alloc/src/vec/mod.rs3
3 files changed, 6 insertions, 2 deletions
diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs
index 4290bb7a8a9..4ad65e678c3 100644
--- a/library/alloc/src/lib.rs
+++ b/library/alloc/src/lib.rs
@@ -107,8 +107,10 @@
 #![feature(char_max_len)]
 #![feature(clone_to_uninit)]
 #![feature(coerce_unsized)]
+#![feature(const_default)]
 #![feature(const_eval_select)]
 #![feature(const_heap)]
+#![feature(const_trait_impl)]
 #![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 187d1ca71d9..58baa07bc17 100644
--- a/library/alloc/src/string.rs
+++ b/library/alloc/src/string.rs
@@ -2611,7 +2611,8 @@ impl_eq! { Cow<'a, str>, &'b str }
 impl_eq! { Cow<'a, str>, String }
 
 #[stable(feature = "rust1", since = "1.0.0")]
-impl Default for String {
+#[rustc_const_unstable(feature = "const_default", issue = "67792")]
+impl const Default for String {
     /// Creates an empty `String`.
     #[inline]
     fn default() -> String {
diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs
index c8341750f4d..9dac58bac4f 100644
--- a/library/alloc/src/vec/mod.rs
+++ b/library/alloc/src/vec/mod.rs
@@ -3895,7 +3895,8 @@ unsafe impl<#[may_dangle] T, A: Allocator> Drop for Vec<T, A> {
 }
 
 #[stable(feature = "rust1", since = "1.0.0")]
-impl<T> Default for Vec<T> {
+#[rustc_const_unstable(feature = "const_default", issue = "67792")]
+impl<T> const Default for Vec<T> {
     /// Creates an empty `Vec<T>`.
     ///
     /// The vector will not allocate until elements are pushed onto it.