-
-
Notifications
You must be signed in to change notification settings - Fork 224
Explicit signal visibility #1075
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
API docs are being generated and will be shortly available at: https://godot-rust.github.io/docs/gdext/pr-1075 |
Nice! I tested the "can't leak private type" case with this diff: diff --git a/itest/rust/src/builtin_tests/containers/signal_test.rs b/itest/rust/src/builtin_tests/containers/signal_test.rs
index 1d11a654..3cc25ef7 100644
--- a/itest/rust/src/builtin_tests/containers/signal_test.rs
+++ b/itest/rust/src/builtin_tests/containers/signal_test.rs
@@ -259,6 +259,20 @@ mod emitter {
pub last_received_int: i64,
}
+ #[derive(GodotClass)]
+ #[class(init, base=Object)]
+ struct Emitter2 {
+ _base: Base<Object>,
+ #[cfg(since_api = "4.2")]
+ pub last_received_int: i64,
+ }
+
+ #[godot_api]
+ impl Emitter2 {
+ #[signal]
+ pub fn signal_int_2(arg1: i64);
+ }
+
#[godot_api]
impl Emitter {
#[signal] and I do see the expected error:
Ideally the error would point to the line with the signal definition instead of the line with |
This looks good to me. If I accidentally forget pub/pub(crate), the compile-time error will indicate which signal is private. error: type `__godot_Signal_CardCostArea_discard_cost_cards<'_>` is private
--> src\class\card_hand.rs:82:9
|
82 | / card_cost_area
83 | | .signals()
84 | | .discard_cost_cards()
| |_________________________________^ private type |
Yes, as mentioned in the initial post, I'm aware of the bad UX here. There are a few things holding me back:
|
Yes, this part is quite nice. It's the "accidentally left a signal |
Fixes #1073.
New semantics:
#[signal]
declarations can now have a visibility specifier:pub
,pub(crate)
, etc.signals().my_sig()
accessor method inherit this visibility.Warning
#[signal]
visibility must not exceed class visibility.Otherwise it will lead to an error message:
pointing to the class macro (not the signal). I'm aware this is not the best UX, but I don't know of any better approach. Suggestions welcome.
The core problem is that the generated signal struct has a
Deref
impl toTypedSignal<C, ...>
, whereC
is the declaring class. So if the signal struct had wider visibility thanC
, it would implicitly make the other type public, which rustc doesn't like. Maybe there's a trick here... See also #1061 (comment).