about summary refs log tree commit diff
path: root/library/alloc/src
diff options
context:
space:
mode:
authorDeadbeef <ent3rm4n@gmail.com>2021-08-14 16:35:12 +0000
committerDeadbeef <ent3rm4n@gmail.com>2021-08-17 07:15:54 +0000
commitb5afa6807b868bc8bb2e6f972629769b150ffd41 (patch)
tree4abfdf049ab0964aa14b4137fe4446d019169939 /library/alloc/src
parent3b5df014390dcef66cc35f968fe51e9558e6ca13 (diff)
downloadrust-b5afa6807b868bc8bb2e6f972629769b150ffd41.tar.gz
rust-b5afa6807b868bc8bb2e6f972629769b150ffd41.zip
Constified `Default` implementations
The libs-api team agrees to allow const_trait_impl to appear in the
standard library as long as stable code cannot be broken (they are
properly gated) this means if the compiler teams thinks it's okay, then
it's okay.

My priority on constifying would be:

	1. Non-generic impls (e.g. Default) or generic impls with no
	   bounds
	2. Generic functions with bounds (that use const impls)
	3. Generic impls with bounds
	4. Impls for traits with associated types

For people opening constification PRs: please cc me and/or oli-obk.
Diffstat (limited to 'library/alloc/src')
-rw-r--r--library/alloc/src/lib.rs1
-rw-r--r--library/alloc/src/string.rs3
-rw-r--r--library/alloc/src/vec/mod.rs3
3 files changed, 5 insertions, 2 deletions
diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs
index d2ececaa975..1a387f291cc 100644
--- a/library/alloc/src/lib.rs
+++ b/library/alloc/src/lib.rs
@@ -95,6 +95,7 @@
 #![feature(const_fn_trait_bound)]
 #![feature(cow_is_borrowed)]
 #![feature(const_cow_is_borrowed)]
+#![feature(const_trait_impl)]
 #![feature(destructuring_assignment)]
 #![feature(dispatch_from_dyn)]
 #![feature(core_intrinsics)]
diff --git a/library/alloc/src/string.rs b/library/alloc/src/string.rs
index 9aefd882af4..6568d9f9907 100644
--- a/library/alloc/src/string.rs
+++ b/library/alloc/src/string.rs
@@ -2105,7 +2105,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_impls", issue = "87864")]
+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 933361d812c..87a0d371815 100644
--- a/library/alloc/src/vec/mod.rs
+++ b/library/alloc/src/vec/mod.rs
@@ -2758,7 +2758,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_impls", issue = "87864")]
+impl<T> const Default for Vec<T> {
     /// Creates an empty `Vec<T>`.
     fn default() -> Vec<T> {
         Vec::new()