File tree Expand file tree Collapse file tree 2 files changed +13
-6
lines changed Expand file tree Collapse file tree 2 files changed +13
-6
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ use core::ops::{Add, AddAssign};
11
11
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
12
12
pub use core:: borrow:: { Borrow , BorrowMut } ;
13
13
14
- use crate :: fmt;
14
+ use crate :: { fmt, DEFAULT_COOP_PREFERRED , alloc :: Global } ;
15
15
#[ cfg( not( no_global_oom_handling) ) ]
16
16
use crate :: string:: String ;
17
17
35
35
/// from any borrow of a given type.
36
36
#[ cfg_attr( not( test) , rustc_diagnostic_item = "ToOwned" ) ]
37
37
#[ 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
+ {
39
43
/// The resulting type after obtaining ownership.
40
44
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
41
45
type Owned : Borrow < Self > ;
Original file line number Diff line number Diff line change @@ -208,14 +208,17 @@ impl BorrowMut<str> for String {
208
208
209
209
#[ cfg( not( no_global_oom_handling) ) ]
210
210
#[ 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 > ;
213
216
#[ inline]
214
- fn to_owned ( & self ) -> String {
217
+ fn to_owned ( & self ) -> String < COOP_PREFERRED > {
215
218
unsafe { String :: from_utf8_unchecked ( self . as_bytes ( ) . to_owned ( ) ) }
216
219
}
217
220
218
- fn clone_into ( & self , target : & mut String ) {
221
+ fn clone_into ( & self , target : & mut String < COOP_PREFERRED > ) {
219
222
let mut b = mem:: take ( target) . into_bytes ( ) ;
220
223
self . as_bytes ( ) . clone_into ( & mut b) ;
221
224
* target = unsafe { String :: from_utf8_unchecked ( b) }
You can’t perform that action at this time.
0 commit comments