Skip to content

Commit 1a22ac1

Browse files
committed
Reduce usage of __emit_struct
1 parent 0870a26 commit 1a22ac1

13 files changed

+64
-77
lines changed

crates/objc2/src/macros/extern_class.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -338,14 +338,11 @@ macro_rules! __inner_extern_class {
338338
$(const NAME: &'static str = $name_const:expr;)?
339339
}
340340
) => {
341-
$crate::__emit_struct! {
342-
($(#[$m])*)
343-
($v)
344-
($name<$($t_struct $(: $(?$b_sized_struct)? $($b_struct)? $(= $default)?)?),*>)
345-
(
346-
$superclass_field: $superclass_field_ty,
347-
$($fields)*
348-
)
341+
$(#[$m])*
342+
#[repr(C)]
343+
$v struct $name<$($t_struct $(: $(?$b_sized_struct)? $($b_struct)? $(= $default)?)?),*> {
344+
$superclass_field: $superclass_field_ty,
345+
$($fields)*
349346
}
350347

351348
$crate::__extern_class_impl_traits! {

crates/objc2/src/runtime/nsobject.rs

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,21 @@ use crate::runtime::{AnyClass, AnyObject, ProtocolObject};
77
use crate::{extern_methods, msg_send, msg_send_id, Message};
88
use crate::{ClassType, ProtocolType};
99

10-
crate::__emit_struct! {
11-
(
12-
/// The root class of most Objective-C class hierarchies.
13-
///
14-
/// This represents the [`NSObject` class][cls]. The name "NSObject" also
15-
/// refers to a protocol, see [`NSObjectProtocol`] for that.
16-
///
17-
/// Since this class is only available with the `Foundation` framework,
18-
/// `objc2` links to it for you.
19-
///
20-
/// This is exported under `icrate::Foundation::NSObject`, you probably
21-
/// want to use that path instead.
22-
///
23-
/// [cls]: https://developer.apple.com/documentation/objectivec/nsobject?language=objc
24-
)
25-
(pub)
26-
(NSObject)
27-
(
28-
__inner: AnyObject,
29-
)
10+
/// The root class of most Objective-C class hierarchies.
11+
///
12+
/// This represents the [`NSObject` class][cls]. The name "NSObject" also
13+
/// refers to a protocol, see [`NSObjectProtocol`] for that.
14+
///
15+
/// Since this class is only available with the `Foundation` framework,
16+
/// `objc2` links to it for you.
17+
///
18+
/// This is exported under `icrate::Foundation::NSObject`, you probably
19+
/// want to use that path instead.
20+
///
21+
/// [cls]: https://developer.apple.com/documentation/objectivec/nsobject?language=objc
22+
#[repr(C)]
23+
pub struct NSObject {
24+
__inner: AnyObject,
3025
}
3126

3227
crate::__extern_class_impl_traits! {

crates/objc2/src/runtime/nsproxy.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,15 @@ use crate::mutability::Root;
55
use crate::runtime::{AnyClass, AnyObject, NSObjectProtocol, ProtocolObject};
66
use crate::ClassType;
77

8-
crate::__emit_struct! {
9-
(
10-
/// An abstract superclass defining an API for objects that act as
11-
/// stand-ins for other objects or for objects that don’t exist yet.
12-
///
13-
/// See [Apple's documentation][apple-doc] for more information.
14-
///
15-
/// [apple-doc]: https://developer.apple.com/documentation/foundation/nsproxy?language=objc
16-
)
17-
(pub)
18-
(NSProxy)
19-
(
20-
__inner: AnyObject,
21-
)
8+
/// An abstract superclass defining an API for objects that act as
9+
/// stand-ins for other objects or for objects that don’t exist yet.
10+
///
11+
/// See [Apple's documentation][apple-doc] for more information.
12+
///
13+
/// [apple-doc]: https://developer.apple.com/documentation/foundation/nsproxy?language=objc
14+
#[repr(C)]
15+
pub struct NSProxy {
16+
__inner: AnyObject,
2217
}
2318

2419
crate::__extern_class_impl_traits! {

crates/test-ui/ui/declare_class_invalid_receiver.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,11 @@ error[E0277]: the trait bound `AnyClass: Message` is not satisfied
115115
= help: the following other types implement trait `Message`:
116116
CustomObject
117117
Exception
118+
NSObject
119+
__NSProxy
118120
ProtocolObject<P>
119121
AnyObject
120122
__RcTestObject
121-
NSObject
122-
__NSProxy
123123
note: required by a bound in `ClassBuilder::add_method`
124124
--> $WORKSPACE/crates/objc2/src/declare/mod.rs
125125
|

crates/test-ui/ui/extern_class_root.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ error[E0277]: the trait bound `MyObject: ClassType` is not satisfied
1212
|
1313
= help: the following other types implement trait `ClassType`:
1414
MyRootClass
15-
__RcTestObject
1615
NSObject
1716
__NSProxy
17+
__RcTestObject
1818
= note: this error originates in the macro `$crate::__inner_extern_class` which comes from the expansion of the macro `extern_class` (in Nightly builds, run with -Z macro-backtrace for more info)

crates/test-ui/ui/implement_protocol_missing_super.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ error[E0277]: the trait bound `CustomObject: NSObjectProtocol` is not satisfied
55
| ^^^^^^^^^^^^ the trait `NSObjectProtocol` is not implemented for `CustomObject`
66
|
77
= help: the following other types implement trait `NSObjectProtocol`:
8-
ProtocolObject<T>
98
NSObject
109
__NSProxy
10+
ProtocolObject<T>
1111
NSApplication
1212
NSCollectionView
1313
NSCollectionLayoutSection

crates/test-ui/ui/msg_send_id_invalid_return.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ error[E0277]: the trait bound `AnyClass: Message` is not satisfied
2626
|
2727
= help: the following other types implement trait `Message`:
2828
Exception
29+
NSObject
30+
__NSProxy
2931
ProtocolObject<P>
3032
AnyObject
3133
__RcTestObject
32-
NSObject
33-
__NSProxy
3434
= note: required for `RetainSemantics<1>` to implement `MsgSendId<&AnyClass, Option<Id<AnyClass>>>`
3535

3636
error[E0277]: the trait bound `AnyClass: Message` is not satisfied
@@ -44,11 +44,11 @@ error[E0277]: the trait bound `AnyClass: Message` is not satisfied
4444
|
4545
= help: the following other types implement trait `Message`:
4646
Exception
47+
NSObject
48+
__NSProxy
4749
ProtocolObject<P>
4850
AnyObject
4951
__RcTestObject
50-
NSObject
51-
__NSProxy
5252
= note: required for `RetainSemantics<1>` to implement `MsgSendId<&AnyClass, Option<Id<AnyClass>>>`
5353

5454
error[E0277]: the trait bound `&AnyObject: MaybeUnwrap` is not satisfied
@@ -79,11 +79,11 @@ error[E0277]: the trait bound `AnyClass: Message` is not satisfied
7979
|
8080
= help: the following other types implement trait `Message`:
8181
Exception
82+
NSObject
83+
__NSProxy
8284
ProtocolObject<P>
8385
AnyObject
8486
__RcTestObject
85-
NSObject
86-
__NSProxy
8787
= note: required for `RetainSemantics<2>` to implement `MsgSendId<&AnyClass, Allocated<AnyClass>>`
8888

8989
error[E0271]: type mismatch resolving `<Id<AnyObject> as MaybeUnwrap>::Input == Allocated<_>`

crates/test-ui/ui/msg_send_invalid_error.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ error[E0277]: the trait bound `i32: Message` is not satisfied
3636
|
3737
= help: the following other types implement trait `Message`:
3838
Exception
39+
NSObject
40+
__NSProxy
3941
ProtocolObject<P>
4042
AnyObject
4143
__RcTestObject
42-
NSObject
43-
__NSProxy
4444
NSApplication
4545
NSCollectionView
4646
and $N others

crates/test-ui/ui/msg_send_super_not_classtype.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ error[E0277]: the trait bound `AnyObject: ClassType` is not satisfied
88
| required by a bound introduced by this call
99
|
1010
= help: the following other types implement trait `ClassType`:
11-
__RcTestObject
1211
NSObject
1312
__NSProxy
13+
__RcTestObject
1414
note: required by a bound in `send_super_message_static`
1515
--> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send.rs
1616
|
@@ -30,9 +30,9 @@ error[E0277]: the trait bound `AnyObject: ClassType` is not satisfied
3030
| required by a bound introduced by this call
3131
|
3232
= help: the following other types implement trait `ClassType`:
33-
__RcTestObject
3433
NSObject
3534
__NSProxy
35+
__RcTestObject
3636
note: required by a bound in `send_super_message_static`
3737
--> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send.rs
3838
|

crates/test-ui/ui/mutability_traits_unimplementable2.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ error[E0277]: the trait bound `CustomStruct: ClassType` is not satisfied
55
| ^^^^^^^^^^^^ the trait `ClassType` is not implemented for `CustomStruct`
66
|
77
= help: the following other types implement trait `ClassType`:
8-
__RcTestObject
98
NSObject
109
__NSProxy
10+
__RcTestObject
1111
= note: required for `CustomStruct` to implement `mutability::private_traits::Sealed`
1212
note: required by a bound in `IsIdCloneable`
1313
--> $WORKSPACE/crates/objc2/src/mutability.rs
@@ -23,9 +23,9 @@ error[E0277]: the trait bound `CustomStruct: ClassType` is not satisfied
2323
| ^^^^^^^^^^^^ the trait `ClassType` is not implemented for `CustomStruct`
2424
|
2525
= help: the following other types implement trait `ClassType`:
26-
__RcTestObject
2726
NSObject
2827
__NSProxy
28+
__RcTestObject
2929
= note: required for `CustomStruct` to implement `IsAllowedMutable`
3030
note: required by a bound in `IsMutable`
3131
--> $WORKSPACE/crates/objc2/src/mutability.rs

0 commit comments

Comments
 (0)