@@ -112,8 +112,8 @@ struct SignalDetails<'a> {
112
112
individual_struct_name : Ident ,
113
113
/// Visibility, e.g. `pub(crate)`
114
114
vis_marker : Option < venial:: VisMarker > ,
115
- /// Detected visibility as strongly typed enum.
116
- vis_classified : SignalVisibility ,
115
+ // // / Detected visibility as strongly typed enum.
116
+ // vis_classified: SignalVisibility,
117
117
}
118
118
119
119
impl < ' a > SignalDetails < ' a > {
@@ -150,7 +150,7 @@ impl<'a> SignalDetails<'a> {
150
150
let individual_struct_name = format_ident ! ( "__godot_Signal_{}_{}" , class_name, signal_name) ;
151
151
152
152
let vis_marker = & fn_signature. vis_marker ;
153
- let Some ( vis_classified ) = SignalVisibility :: try_parse ( vis_marker. as_ref ( ) ) else {
153
+ let Some ( _vis_classified ) = SignalVisibility :: try_parse ( vis_marker. as_ref ( ) ) else {
154
154
return bail ! (
155
155
vis_marker,
156
156
"invalid visibility `{}` for #[signal]; supported are `pub`, `pub(crate)`, `pub(super)` and private (no visibility marker)" ,
@@ -170,7 +170,7 @@ impl<'a> SignalDetails<'a> {
170
170
signal_cfg_attrs,
171
171
individual_struct_name,
172
172
vis_marker : vis_marker. clone ( ) ,
173
- vis_classified,
173
+ // vis_classified,
174
174
} )
175
175
}
176
176
}
@@ -187,8 +187,8 @@ pub fn make_signal_registrations(
187
187
188
188
#[ cfg( since_api = "4.2" ) ]
189
189
let mut collection_api = SignalCollection :: default ( ) ;
190
- #[ cfg( since_api = "4.2" ) ]
191
- let mut max_visibility = SignalVisibility :: Priv ;
190
+ // #[cfg(since_api = "4.2")]
191
+ // let mut max_visibility = SignalVisibility::Priv;
192
192
193
193
for signal in signals {
194
194
let SignalDefinition {
@@ -203,15 +203,15 @@ pub fn make_signal_registrations(
203
203
#[ cfg( since_api = "4.2" ) ]
204
204
if * has_builder {
205
205
collection_api. extend_with ( & details) ;
206
- max_visibility = max_visibility. max ( details. vis_classified ) ;
206
+ // max_visibility = max_visibility.max(details.vis_classified);
207
207
}
208
208
209
209
let registration = make_signal_registration ( & details, class_name_obj) ;
210
210
signal_registrations. push ( registration) ;
211
211
}
212
212
213
213
#[ cfg( since_api = "4.2" ) ]
214
- let signal_symbols = make_signal_symbols ( class_name, collection_api, max_visibility ) ;
214
+ let signal_symbols = make_signal_symbols ( class_name, collection_api) ;
215
215
#[ cfg( before_api = "4.2" ) ]
216
216
let signal_symbols = None ;
217
217
@@ -391,7 +391,7 @@ fn make_signal_individual_struct(details: &SignalDetails) -> TokenStream {
391
391
fn make_signal_symbols (
392
392
class_name : & Ident ,
393
393
collection_api : SignalCollection ,
394
- max_visibility : SignalVisibility ,
394
+ // max_visibility: SignalVisibility,
395
395
) -> Option < TokenStream > {
396
396
// Future note: if we add Rust->Rust inheritance, then the WithSignals trait must be unconditionally implemented.
397
397
if collection_api. is_empty ( ) {
@@ -405,8 +405,13 @@ fn make_signal_symbols(
405
405
let individual_structs = collection_api. individual_structs ;
406
406
407
407
// The collection cannot be `pub` because `Deref::Target` contains the class type, which leads to "leak private type" errors.
408
- // Max visibility: the user decides which visibility is acceptable for individual #[signal]s, which is bounded by the class' own
409
- // visibility. Since we assume that decision is correct, the collection itself can also share the widest visibility of any #[signal].
408
+ // We thus adopt the visibility of the #[derive(GodotClass)] struct, imported via macro trick.
409
+ //
410
+ // A previous approach (that cannot access the struct visibility) used "max visibility": the user decides which visibility is acceptable f
411
+ // or individual #[signal]s. They can all be at most the class visibility. Since we assume that decision is correct, the signal collection
412
+ // itself can also share the widest visibility of any #[signal]. This approach however still led to problems because there's a 2-way
413
+ // dependency: `impl WithSignals for MyClass` has an associated type `SignalCollection` that mentions the generated collection type. If
414
+ // that collection type has *lower* visibility than the class, we *also* run into "leak private type" errors.
410
415
411
416
// Unrelated, we could use the following for encapsulation:
412
417
// #[cfg(since_api = "4.2")]
@@ -430,13 +435,17 @@ fn make_signal_symbols(
430
435
// Downside is slightly higher complexity and introducing signals in secondary blocks becomes harder (although we could use another
431
436
// module name, we'd need a way to create unique names).
432
437
438
+ let visibility_macro = util:: format_class_visibility_macro ( class_name) ;
439
+
433
440
let code = quote ! {
434
- #[ allow( non_camel_case_types) ]
435
- #[ doc( hidden) ] // Only on struct, not methods, to allow completion in IDEs.
436
- #max_visibility struct #collection_struct_name<' c, C > {
437
- // Hiding necessary because it's in the same scope as the user-defined class, so appearing in IDE completion.
438
- #[ doc( hidden) ]
439
- __internal_obj: Option <:: godot:: private:: UserSignalObject <' c, C >>
441
+ #visibility_macro! {
442
+ #[ allow( non_camel_case_types) ]
443
+ #[ doc( hidden) ] // Only on struct, not methods, to allow completion in IDEs.
444
+ struct #collection_struct_name<' c, C > {
445
+ // Hiding necessary because it's in the same scope as the user-defined class, so appearing in IDE completion.
446
+ #[ doc( hidden) ]
447
+ __internal_obj: Option <:: godot:: private:: UserSignalObject <' c, C >>
448
+ }
440
449
}
441
450
442
451
impl <' c, C > #collection_struct_name<' c, C >
0 commit comments