@@ -1431,30 +1431,19 @@ impl PointeeTy {
14311431 }
14321432
14331433 fn is_cf_type ( & self ) -> bool {
1434- match self {
1435- // Recurse into typedefs
1436- Self :: TypeDef { to, .. } => to. is_cf_type ( ) ,
1437- Self :: CFTypeDef { .. } => true ,
1438- _ => false ,
1439- }
1434+ matches ! ( self . through_typedef( ) , Self :: CFTypeDef { .. } )
14401435 }
14411436
14421437 fn is_dispatch_type ( & self ) -> bool {
1443- match self {
1444- // Recurse into typedefs
1445- Self :: TypeDef { to, .. } => to. is_dispatch_type ( ) ,
1446- Self :: DispatchTypeDef { .. } => true ,
1447- _ => false ,
1448- }
1438+ matches ! ( self . through_typedef( ) , Self :: DispatchTypeDef { .. } )
14491439 }
14501440
14511441 fn is_network_type ( & self ) -> bool {
1452- match self {
1453- // Recurse into typedefs
1454- Self :: TypeDef { to, .. } => to. is_network_type ( ) ,
1455- Self :: NetworkTypeDef { .. } => true ,
1456- _ => false ,
1457- }
1442+ matches ! ( self . through_typedef( ) , Self :: NetworkTypeDef { .. } )
1443+ }
1444+
1445+ fn is_block_type ( & self ) -> bool {
1446+ matches ! ( self . through_typedef( ) , Self :: Block { .. } )
14581447 }
14591448
14601449 fn is_subtype_of ( & self , other : & Self ) -> bool {
@@ -2476,10 +2465,7 @@ impl Ty {
24762465 * * pointee = Self :: Pointee ( PointeeTy :: TypeDef { id, to } ) ;
24772466 return inner;
24782467 } else {
2479- error ! (
2480- ?pointee,
2481- "is_object_like/is_cf_type/is_os_type but not Pointee"
2482- ) ;
2468+ error ! ( ?pointee, "is_object_like but not Pointee" ) ;
24832469 }
24842470 }
24852471 } else {
@@ -2947,6 +2933,7 @@ impl Ty {
29472933 || self . is_cf_type ( )
29482934 || self . is_dispatch_type ( )
29492935 || self . is_network_type ( )
2936+ || self . is_block_type ( )
29502937 }
29512938
29522939 /// Determine whether the inner type of a `Pointer` is object-like.
@@ -2985,6 +2972,15 @@ impl Ty {
29852972 }
29862973 }
29872974
2975+ /// Determine whether the inner type of a `Pointer` is a block.
2976+ fn is_block_type ( & self ) -> bool {
2977+ if let Self :: Pointee ( pointee_ty) = self . through_typedef ( ) {
2978+ pointee_ty. is_block_type ( )
2979+ } else {
2980+ false
2981+ }
2982+ }
2983+
29882984 /// Determine whether the pointee inside a `Pointer` is the inner
29892985 /// struct/void type required for a type to be considered a CF type.
29902986 ///
@@ -3257,13 +3253,23 @@ impl Ty {
32573253 write ! ( f, " -> Option<&'static {}>" , pointee. behind_pointer( true ) )
32583254 }
32593255 }
3256+ Self :: Pointer {
3257+ nullability : _,
3258+ lifetime : _, // TODO
3259+ bounds : PointerBounds :: Single ,
3260+ pointee,
3261+ ..
3262+ } if pointee. is_block_type ( ) => {
3263+ // TODO: Emit `RcBlock` or similar.
3264+ write ! ( f, " -> {}" , self . plain( true ) )
3265+ }
32603266 Self :: Pointer {
32613267 nullability,
32623268 lifetime : _, // TODO: Use this somehow?
32633269 bounds : PointerBounds :: Single ,
32643270 pointee,
32653271 ..
3266- } if pointee. is_object_like ( ) && !pointee . is_static_object ( ) => {
3272+ } if pointee. is_object_like ( ) => {
32673273 // NOTE: We return CF types as `Retained` for now, since we
32683274 // don't have support for the CF wrapper in msg_send! yet.
32693275 if * nullability == Nullability :: NonNull {
@@ -3324,7 +3330,7 @@ impl Ty {
33243330 bounds : PointerBounds :: Single ,
33253331 pointee,
33263332 ..
3327- } if pointee. is_object_like ( ) => {
3333+ } if pointee. is_object_like ( ) && !pointee . is_block_type ( ) => {
33283334 // NULL -> error
33293335 Box :: new ( move |f| {
33303336 write ! (
@@ -4038,18 +4044,22 @@ impl Ty {
40384044 * no_escape = arg_no_escape;
40394045 arg_no_escape = false ;
40404046 }
4047+ // Ignore `arg_no_escape` on typedefs for now.
4048+ Self :: Pointee ( PointeeTy :: TypeDef { .. } ) => {
4049+ arg_no_escape = false ;
4050+ }
40414051 _ => { }
40424052 } ,
4043- // Ignore typedefs for now
4053+ // Ignore `arg_no_escape` on typedefs for now.
40444054 Self :: TypeDef { .. } => {
4045- arg_sendable = None ;
40464055 arg_no_escape = false ;
40474056 }
40484057 _ => { }
40494058 }
40504059
40514060 if arg_sendable. is_some ( ) {
4052- warn ! ( ?ty, "did not consume sendable in argument" ) ;
4061+ // Important for soundness.
4062+ error ! ( ?ty, "did not consume sendable in argument" ) ;
40534063 }
40544064
40554065 if arg_no_escape {
@@ -4347,7 +4357,8 @@ impl Ty {
43474357
43484358 pub ( crate ) fn is_retainable ( & self ) -> bool {
43494359 if let Self :: Pointer { pointee, .. } = self {
4350- pointee. is_object_like ( ) && !pointee. is_static_object ( )
4360+ // Unsure if static items and blocks should be considered retainable?
4361+ pointee. is_object_like ( ) && !pointee. is_static_object ( ) && !pointee. is_block_type ( )
43514362 } else {
43524363 false
43534364 }
@@ -4386,7 +4397,7 @@ impl Ty {
43864397 Self :: Struct { fields, .. } | Self :: Union { fields, .. } => {
43874398 fields. iter ( ) . any ( |( _, field) | field. needs_simd ( ) )
43884399 }
4389- Self :: Pointee (
4400+ Self :: Pointee ( pointee ) => match pointee . through_typedef ( ) {
43904401 PointeeTy :: Fn {
43914402 result_type,
43924403 arguments,
@@ -4396,8 +4407,9 @@ impl Ty {
43964407 result_type,
43974408 arguments,
43984409 ..
4399- } ,
4400- ) => result_type. needs_simd ( ) || arguments. iter ( ) . any ( |arg| arg. needs_simd ( ) ) ,
4410+ } => result_type. needs_simd ( ) || arguments. iter ( ) . any ( |arg| arg. needs_simd ( ) ) ,
4411+ _ => false ,
4412+ } ,
44014413 _ => false ,
44024414 }
44034415 }
0 commit comments