1- use crate :: rc:: { Id , Ownership } ;
1+ use crate :: rc:: { Allocated , Id , Ownership } ;
22use crate :: runtime:: { Class , Sel } ;
33use crate :: { Message , MessageArguments , MessageReceiver } ;
44
@@ -68,8 +68,8 @@ impl<T: ?Sized + Message, O: Ownership> MsgSendId<&'_ Class, Id<T, O>>
6868 }
6969}
7070
71- // `alloc`, should mark the return value as "allocated, not initialized" somehow
72- impl < T : ?Sized + Message , O : Ownership > MsgSendId < & ' _ Class , Id < T , O > >
71+ // `alloc`
72+ impl < T : ?Sized + Message , O : Ownership > MsgSendId < & ' _ Class , Id < Allocated < T > , O > >
7373 for RetainSemantics < false , true , false , false >
7474{
7575 #[ inline]
@@ -78,26 +78,26 @@ impl<T: ?Sized + Message, O: Ownership> MsgSendId<&'_ Class, Id<T, O>>
7878 cls : & Class ,
7979 sel : Sel ,
8080 args : A ,
81- ) -> Option < Id < T , O > > {
81+ ) -> Option < Id < Allocated < T > , O > > {
8282 // SAFETY: Checked by caller
8383 let obj = unsafe { MessageReceiver :: send_message ( cls, sel, args) } ;
8484 // SAFETY: The selector is `alloc`, so this has +1 retain count
85- unsafe { Id :: new ( obj) }
85+ unsafe { Id :: new_allocated ( obj) }
8686 }
8787}
8888
89- // `init`, should mark the input value as "allocated, not initialized" somehow
90- impl < T : ?Sized + Message , O : Ownership > MsgSendId < Option < Id < T , O > > , Id < T , O > >
89+ // `init`
90+ impl < T : ?Sized + Message , O : Ownership > MsgSendId < Option < Id < Allocated < T > , O > > , Id < T , O > >
9191 for RetainSemantics < false , false , true , false >
9292{
9393 #[ inline]
9494 #[ track_caller]
9595 unsafe fn send_message_id < A : MessageArguments > (
96- obj : Option < Id < T , O > > ,
96+ obj : Option < Id < Allocated < T > , O > > ,
9797 sel : Sel ,
9898 args : A ,
9999 ) -> Option < Id < T , O > > {
100- let ptr = Id :: option_into_ptr ( obj) ;
100+ let ptr = Id :: option_into_ptr ( obj. map ( |obj| unsafe { Id :: assume_init ( obj ) } ) ) ;
101101 // SAFETY: `ptr` may be null here, but that's fine since the return
102102 // is `*mut T`, which is one of the few types where messages to nil is
103103 // allowed.
@@ -191,7 +191,7 @@ mod tests {
191191
192192 use core:: ptr;
193193
194- use crate :: rc:: { Owned , RcTestObject , Shared , ThreadTestData } ;
194+ use crate :: rc:: { Allocated , Owned , RcTestObject , Shared , ThreadTestData } ;
195195 use crate :: runtime:: Object ;
196196 use crate :: { Encoding , RefEncode } ;
197197
@@ -200,7 +200,7 @@ mod tests {
200200 let mut expected = ThreadTestData :: current ( ) ;
201201 let cls = RcTestObject :: class ( ) ;
202202
203- let obj: Id < RcTestObject , Shared > = unsafe { msg_send_id ! [ cls, alloc] . unwrap ( ) } ;
203+ let obj: Id < Allocated < RcTestObject > , Shared > = unsafe { msg_send_id ! [ cls, alloc] . unwrap ( ) } ;
204204 expected. alloc += 1 ;
205205 expected. assert_current ( ) ;
206206
@@ -230,7 +230,7 @@ mod tests {
230230 let cls = RcTestObject :: class ( ) ;
231231
232232 let zone: * const _NSZone = ptr:: null ( ) ;
233- let _obj: Id < RcTestObject , Owned > =
233+ let _obj: Id < Allocated < RcTestObject > , Owned > =
234234 unsafe { msg_send_id ! [ cls, allocWithZone: zone] . unwrap ( ) } ;
235235 // `+[NSObject alloc]` delegates to `+[NSObject allocWithZone:]`, but
236236 // `RcTestObject` only catches `alloc`.
@@ -243,14 +243,14 @@ mod tests {
243243 let mut expected = ThreadTestData :: current ( ) ;
244244 let cls = RcTestObject :: class ( ) ;
245245
246- let obj: Option < Id < RcTestObject , Shared > > = unsafe { msg_send_id ! [ cls, alloc] } ;
246+ let obj: Option < Id < Allocated < RcTestObject > , Shared > > = unsafe { msg_send_id ! [ cls, alloc] } ;
247247 expected. alloc += 1 ;
248248 // Don't check allocation error
249249 let _obj: Id < RcTestObject , Shared > = unsafe { msg_send_id ! [ obj, init] . unwrap ( ) } ;
250250 expected. init += 1 ;
251251 expected. assert_current ( ) ;
252252
253- let obj: Option < Id < RcTestObject , Shared > > = unsafe { msg_send_id ! [ cls, alloc] } ;
253+ let obj: Option < Id < Allocated < RcTestObject > , Shared > > = unsafe { msg_send_id ! [ cls, alloc] } ;
254254 expected. alloc += 1 ;
255255 // Check allocation error before init
256256 let obj = obj. unwrap ( ) ;
0 commit comments