Skip to content

Commit 81b0331

Browse files
added Default impls
1 parent 7f2fc33 commit 81b0331

File tree

4 files changed

+84
-0
lines changed

4 files changed

+84
-0
lines changed

library/alloc/src/ffi/c_str.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,28 @@ impl From<&CStr> for Rc<CStr> {
909909
}
910910
}
911911

912+
#[cfg(not(no_global_oom_handling))]
913+
#[stable(feature = "rust1", since = "1.0.0")]
914+
impl Default for Arc<CStr> {
915+
/// Creates an empty CStr inside an Arc
916+
#[inline]
917+
fn default() -> Self {
918+
let c_str: &CStr = Default::default();
919+
Arc::from(c_str)
920+
}
921+
}
922+
923+
#[cfg(not(no_global_oom_handling))]
924+
#[stable(feature = "rust1", since = "1.0.0")]
925+
impl Default for Rc<CStr> {
926+
/// Creates an empty CStr inside an Rc
927+
#[inline]
928+
fn default() -> Self {
929+
let c_str: &CStr = Default::default();
930+
Rc::from(c_str)
931+
}
932+
}
933+
912934
#[cfg(not(test))]
913935
#[stable(feature = "default_box_extra", since = "1.17.0")]
914936
impl Default for Box<CStr> {

library/alloc/src/rc.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2226,6 +2226,27 @@ impl<T: Default> Default for Rc<T> {
22262226
}
22272227
}
22282228

2229+
#[cfg(not(no_global_oom_handling))]
2230+
#[stable(feature = "rust1", since = "1.0.0")]
2231+
impl Default for Rc<str> {
2232+
/// Creates an empty str inside an Rc
2233+
#[inline]
2234+
fn default() -> Self {
2235+
Rc::from("")
2236+
}
2237+
}
2238+
2239+
#[cfg(not(no_global_oom_handling))]
2240+
#[stable(feature = "rust1", since = "1.0.0")]
2241+
impl<T> Default for Rc<[T]> {
2242+
/// Creates an empty [T] inside an Rc
2243+
#[inline]
2244+
fn default() -> Self {
2245+
let arr: [T; 0] = [];
2246+
Rc::from(arr)
2247+
}
2248+
}
2249+
22292250
#[stable(feature = "rust1", since = "1.0.0")]
22302251
trait RcEqIdent<T: ?Sized + PartialEq, A: Allocator> {
22312252
fn eq(&self, other: &Rc<T, A>) -> bool;

library/alloc/src/sync.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3298,6 +3298,27 @@ impl<T: Default> Default for Arc<T> {
32983298
}
32993299
}
33003300

3301+
#[cfg(not(no_global_oom_handling))]
3302+
#[stable(feature = "rust1", since = "1.0.0")]
3303+
impl Default for Arc<str> {
3304+
/// Creates an empty str inside an Arc
3305+
#[inline]
3306+
fn default() -> Self {
3307+
Arc::from("")
3308+
}
3309+
}
3310+
3311+
#[cfg(not(no_global_oom_handling))]
3312+
#[stable(feature = "rust1", since = "1.0.0")]
3313+
impl<T> Default for Arc<[T]> {
3314+
/// Creates an empty [T] inside an Arc
3315+
#[inline]
3316+
fn default() -> Self {
3317+
let arr: [T; 0] = [];
3318+
Arc::from(arr)
3319+
}
3320+
}
3321+
33013322
#[stable(feature = "rust1", since = "1.0.0")]
33023323
impl<T: ?Sized + Hash, A: Allocator> Hash for Arc<T, A> {
33033324
fn hash<H: Hasher>(&self, state: &mut H) {

library/std/src/ffi/os_str.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,6 +1346,26 @@ impl Default for &OsStr {
13461346
}
13471347
}
13481348

1349+
#[stable(feature = "shared_from_slice2", since = "1.24.0")]
1350+
impl Default for Arc<OsStr> {
1351+
/// Creates an empty OsStr inside an Arc
1352+
#[inline]
1353+
fn default() -> Self {
1354+
let os_str: &OsStr = Default::default();
1355+
Arc::from(os_str)
1356+
}
1357+
}
1358+
1359+
#[stable(feature = "shared_from_slice2", since = "1.24.0")]
1360+
impl Default for Rc<OsStr> {
1361+
/// Creates an empty OsStr inside an Rc
1362+
#[inline]
1363+
fn default() -> Self {
1364+
let os_str: &OsStr = Default::default();
1365+
Rc::from(os_str)
1366+
}
1367+
}
1368+
13491369
#[stable(feature = "rust1", since = "1.0.0")]
13501370
impl PartialEq for OsStr {
13511371
#[inline]

0 commit comments

Comments
 (0)