@@ -105,45 +105,46 @@ impl<'a> Cache<'a> {
105
105
}
106
106
} ) ;
107
107
108
- match ( method. is_class , self . mainthreadonly_classes . contains ( id) ) {
109
- // MainThreadOnly class with static method
110
- ( true , true ) => {
111
- // Assume the method needs main thread
112
- result_type_contains_mainthreadonly = true ;
113
- }
114
- // Class with static method
115
- ( true , false ) => {
116
- // Continue with the normal check
117
- }
118
- // MainThreadOnly class with non-static method
119
- ( false , true ) => {
120
- // Method is already required to run on main
121
- // thread, so no need to add MainThreadMarker
122
- continue ;
123
- }
124
- // Class with non-static method
125
- ( false , false ) => {
126
- // Continue with the normal check
127
- }
108
+ let mut any_argument_contains_mainthreadonly: bool = false ;
109
+ for ( _, argument) in method. arguments . iter ( ) {
110
+ // Important: We only visit the top-level types, to not
111
+ // include optional arguments like `Option<&NSView>` or
112
+ // `&NSArray<NSView>`.
113
+ argument. visit_toplevel_types ( & mut |id| {
114
+ if self . mainthreadonly_classes . contains ( id) {
115
+ any_argument_contains_mainthreadonly = true ;
116
+ }
117
+ } ) ;
128
118
}
129
119
130
- if result_type_contains_mainthreadonly {
131
- let mut any_argument_contains_mainthreadonly: bool = false ;
132
- for ( _, argument) in method. arguments . iter ( ) {
133
- // Important: We only visit the top-level types, to not
134
- // include e.g. `Option<&NSView>` or `&NSArray<NSView>`.
135
- argument. visit_toplevel_types ( & mut |id| {
136
- if self . mainthreadonly_classes . contains ( id) {
137
- any_argument_contains_mainthreadonly = true ;
138
- }
139
- } ) ;
120
+ if self . mainthreadonly_classes . contains ( id) {
121
+ if method. is_class {
122
+ // Assume the method needs main thread if it's
123
+ // declared on a main thread only class.
124
+ result_type_contains_mainthreadonly = true ;
125
+ } else {
126
+ // Method takes `&self` or `&mut self`, or is
127
+ // an initialization method, all of which
128
+ // already require the main thread.
129
+ //
130
+ // Note: Initialization methods can be passed
131
+ // `None`, but in that case the return will
132
+ // always be NULL.
133
+ any_argument_contains_mainthreadonly = true ;
140
134
}
135
+ }
141
136
142
- // Apply main thread only, unless a (required)
143
- // argument was main thread only.
144
- if !any_argument_contains_mainthreadonly {
145
- method. mainthreadonly = true ;
146
- }
137
+ if any_argument_contains_mainthreadonly {
138
+ // MainThreadMarker can be retrieved from
139
+ // `MainThreadMarker::from` inside these methods,
140
+ // and hence passing it is redundant.
141
+ method. mainthreadonly = false ;
142
+ } else if result_type_contains_mainthreadonly {
143
+ method. mainthreadonly = true ;
144
+ } else {
145
+ // If neither, then we respect any annotation
146
+ // the method may have had before
147
+ // method.mainthreadonly = method.mainthreadonly;
147
148
}
148
149
}
149
150
}
0 commit comments