Skip to content

Commit ab2b964

Browse files
Fixing A and COOP_PREFERRED generics. WIP...
1 parent e6cb4de commit ab2b964

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

library/alloc/src/borrow.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use core::ops::{Add, AddAssign};
1111
#[stable(feature = "rust1", since = "1.0.0")]
1212
pub use core::borrow::{Borrow, BorrowMut};
1313

14-
use crate::fmt;
14+
use crate::{fmt, DEFAULT_COOP_PREFERRED, alloc::Global};
1515
#[cfg(not(no_global_oom_handling))]
1616
use crate::string::String;
1717

@@ -35,7 +35,11 @@ where
3535
/// from any borrow of a given type.
3636
#[cfg_attr(not(test), rustc_diagnostic_item = "ToOwned")]
3737
#[stable(feature = "rust1", since = "1.0.0")]
38-
pub trait ToOwned {
38+
#[allow(unused_braces)]
39+
pub trait ToOwned<const COOP_PREFERRED: bool = { DEFAULT_COOP_PREFERRED!() } >
40+
where
41+
[(); core::alloc::co_alloc_metadata_num_slots_with_preference::<Global>(COOP_PREFERRED)]:,
42+
{
3943
/// The resulting type after obtaining ownership.
4044
#[stable(feature = "rust1", since = "1.0.0")]
4145
type Owned: Borrow<Self>;

library/alloc/src/str.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,17 @@ impl BorrowMut<str> for String {
208208

209209
#[cfg(not(no_global_oom_handling))]
210210
#[stable(feature = "rust1", since = "1.0.0")]
211-
impl ToOwned for str {
212-
type Owned = String;
211+
impl<const COOP_PREFERRED: bool> ToOwned<COOP_PREFERRED> for str
212+
where
213+
[(); core::alloc::co_alloc_metadata_num_slots_with_preference::<Global>(COOP_PREFERRED)]:,
214+
{
215+
type Owned = String<COOP_PREFERRED>;
213216
#[inline]
214-
fn to_owned(&self) -> String {
217+
fn to_owned(&self) -> String<COOP_PREFERRED> {
215218
unsafe { String::from_utf8_unchecked(self.as_bytes().to_owned()) }
216219
}
217220

218-
fn clone_into(&self, target: &mut String) {
221+
fn clone_into(&self, target: &mut String<COOP_PREFERRED>) {
219222
let mut b = mem::take(target).into_bytes();
220223
self.as_bytes().clone_into(&mut b);
221224
*target = unsafe { String::from_utf8_unchecked(b) }

0 commit comments

Comments
 (0)