Skip to content

Commit 560cdee

Browse files
committed
Remove all places where empty #[godot_api] workaround was in use
1 parent c61a1ba commit 560cdee

File tree

11 files changed

+4
-102
lines changed

11 files changed

+4
-102
lines changed

godot-core/src/lib.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,6 @@ mod gen;
4545

4646
#[doc(hidden)]
4747
pub mod private {
48-
// If someone forgets #[godot_api], this causes a compile error, rather than virtual functions not being called at runtime.
49-
#[allow(non_camel_case_types)]
50-
pub trait You_forgot_the_attribute__godot_api {}
51-
pub use crate::property::Cannot_export_without_godot_api_impl;
52-
5348
use std::sync::{Arc, Mutex};
5449

5550
pub use crate::gen::classes::class_macros;
@@ -59,6 +54,10 @@ pub mod private {
5954

6055
use crate::{log, sys};
6156

57+
// If someone forgets #[godot_api], this causes a compile error, rather than virtual functions not being called at runtime.
58+
#[allow(non_camel_case_types)]
59+
pub trait You_forgot_the_attribute__godot_api {}
60+
6261
sys::plugin_registry!(pub __GODOT_PLUGIN_REGISTRY: ClassPlugin);
6362

6463
pub(crate) fn iterate_plugins(mut visitor: impl FnMut(&ClassPlugin)) {

godot-core/src/property.rs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -106,23 +106,6 @@ impl PropertyHintInfo {
106106
}
107107
}
108108

109-
/// To export properties to Godot, you must have an impl-block with the `#[godot_api]` attribute, even if
110-
/// it is empty.
111-
///
112-
/// This trait is automatically implemented when such an impl-block is present. If Rust complains that it is
113-
/// not implemented, then you can usually fix this by adding:
114-
///
115-
/// ```ignore
116-
/// #[godot_api]
117-
/// impl MyClass {}
118-
/// ```
119-
///
120-
/// Where you replace `MyClass` with the name of your class.
121-
#[allow(non_camel_case_types)]
122-
pub trait Cannot_export_without_godot_api_impl {
123-
const EXISTS: () = ();
124-
}
125-
126109
/// Functions used to translate user-provided arguments into export hints.
127110
pub mod export_info_functions {
128111
use crate::builtin::GString;

godot-macros/src/class/data_models/property.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -203,18 +203,8 @@ pub fn make_property_impl(class_name: &Ident, fields: &Fields) -> TokenStream {
203203
});
204204
}
205205

206-
let enforce_godot_api_impl = if !export_tokens.is_empty() {
207-
quote! {
208-
const MUST_HAVE_GODOT_API_IMPL: () = <#class_name as ::godot::private::Cannot_export_without_godot_api_impl>::EXISTS;
209-
}
210-
} else {
211-
TokenStream::new()
212-
};
213-
214206
quote! {
215207
impl #class_name {
216-
#enforce_godot_api_impl
217-
218208
#(#getter_setter_impls)*
219209
}
220210

godot-macros/src/class/godot_api.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,6 @@ fn transform_inherent_impl(mut original_impl: Impl) -> Result<TokenStream, Error
222222
}
223223
}
224224

225-
impl ::godot::private::Cannot_export_without_godot_api_impl for #class_name {}
226-
227225
::godot::sys::plugin_add!(__GODOT_PLUGIN_REGISTRY in #prv; #prv::ClassPlugin {
228226
class_name: #class_name_obj,
229227
component: #prv::PluginComponent::UserMethodBinds {

godot-macros/src/lib.rs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -124,18 +124,12 @@ use crate::util::ident;
124124
/// #[var]
125125
/// my_field: i64,
126126
/// }
127-
///
128-
/// #[godot_api]
129-
/// impl MyStruct {}
130127
/// ```
131128
///
132129
/// This makes the field accessible in GDScript using `my_struct.my_field` syntax. Additionally, it
133130
/// generates a trivial getter and setter named `get_my_field` and `set_my_field`, respectively.
134131
/// These are `pub` in Rust, since they're exposed from GDScript anyway.
135132
///
136-
/// For technical reasons, an impl-block with the `#[godot_api]` attribute is required for properties to
137-
/// work. Failing to include one will cause a compile error if you try to create any properties.
138-
///
139133
/// If you want to implement your own getter and/or setter, write those as a function on your Rust
140134
/// type, expose it using `#[func]`, and annotate the field with
141135
/// `#[export(get = ..., set = ...)]`:
@@ -196,9 +190,6 @@ use crate::util::ident;
196190
/// #[export]
197191
/// my_field: i64,
198192
/// }
199-
///
200-
/// #[godot_api]
201-
/// impl MyStruct {}
202193
/// ```
203194
///
204195
/// If you dont also include a `#[var]` attribute, then a default one will be generated.
@@ -252,9 +243,6 @@ use crate::util::ident;
252243
/// #[export(flags = (A = 1, B = 2, AB = 3))]
253244
/// flags: u32,
254245
/// }
255-
///
256-
/// #[godot_api]
257-
/// impl MyStruct {}
258246
/// ```
259247
///
260248
/// Most values in expressions like `key = value`, can be an arbitrary expression that evaluates to the
@@ -274,9 +262,6 @@ use crate::util::ident;
274262
/// #[export(flags = (A = 0b0001, B = 0b0010, C = 0b0100, D = 0b1000))]
275263
/// flags: u32,
276264
/// }
277-
///
278-
/// #[godot_api]
279-
/// impl MyStruct {}
280265
/// ```
281266
///
282267
/// You can specify custom property hints, hint strings, and usage flags in a `#[var]` attribute using the
@@ -297,9 +282,6 @@ use crate::util::ident;
297282
/// )]
298283
/// my_field: i64,
299284
/// }
300-
///
301-
/// #[godot_api]
302-
/// impl MyStruct {}
303285
/// ```
304286
///
305287
///
@@ -541,10 +523,6 @@ pub fn derive_from_godot(input: TokenStream) -> TokenStream {
541523
/// foo: TestEnum
542524
/// }
543525
///
544-
/// # //TODO: remove this when https://github.com/godot-rust/gdext/issues/187 is truly addressed
545-
/// # #[godot_api]
546-
/// # impl TestClass {}
547-
///
548526
/// # fn main() {
549527
/// let mut class = TestClass {foo: TestEnum::B};
550528
/// assert_eq!(class.get_foo(), TestEnum::B as i32);

itest/rust/build.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -457,9 +457,6 @@ fn generate_property_template(inputs: &[Input]) -> PropertyTests {
457457
#[export(enum = (Rebecca, Mary, Leah))]
458458
export_enum_string_rebecca_mary_leah: GString,
459459
}
460-
461-
#[godot_api]
462-
impl PropertyTestsRust {}
463460
};
464461

465462
let gdscript = format!(

itest/rust/src/object_tests/object_test.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -844,19 +844,13 @@ pub mod object_test_gd {
844844
i: i64,
845845
}
846846

847-
#[godot_api]
848-
impl MockObjRust {}
849-
850847
#[derive(GodotClass)]
851848
#[class(init, base=RefCounted)]
852849
struct MockRefCountedRust {
853850
#[var]
854851
i: i64,
855852
}
856853

857-
#[godot_api]
858-
impl MockRefCountedRust {}
859-
860854
#[derive(GodotClass, Debug)]
861855
#[class(init, base=RefCounted)]
862856
struct ObjectTest;

itest/rust/src/object_tests/property_test.rs

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -298,9 +298,6 @@ struct CheckAllExports {
298298
color_no_alpha: Color,
299299
}
300300

301-
#[godot_api]
302-
impl CheckAllExports {}
303-
304301
#[repr(i64)]
305302
#[derive(Property, Export, Eq, PartialEq, Debug)]
306303
pub enum TestEnum {
@@ -315,9 +312,6 @@ pub struct DeriveProperty {
315312
pub foo: TestEnum,
316313
}
317314

318-
#[godot_api]
319-
impl DeriveProperty {}
320-
321315
#[itest]
322316
fn derive_property() {
323317
let mut class = DeriveProperty { foo: TestEnum::B };
@@ -335,9 +329,6 @@ pub struct DeriveExport {
335329
pub base: Base<RefCounted>,
336330
}
337331

338-
#[godot_api]
339-
impl DeriveExport {}
340-
341332
#[godot_api]
342333
impl IRefCounted for DeriveExport {
343334
fn init(base: godot::obj::Base<Self::Base>) -> Self {
@@ -373,22 +364,10 @@ fn derive_export() {
373364
#[class(init, base=Resource)]
374365
pub struct CustomResource {}
375366

376-
#[godot_api]
377-
impl CustomResource {}
378-
379-
#[godot_api]
380-
impl IResource for CustomResource {}
381-
382367
#[derive(GodotClass)]
383368
#[class(init, base=Resource, rename=NewNameCustomResource)]
384369
pub struct RenamedCustomResource {}
385370

386-
#[godot_api]
387-
impl RenamedCustomResource {}
388-
389-
#[godot_api]
390-
impl IResource for RenamedCustomResource {}
391-
392371
#[derive(GodotClass)]
393372
#[class(init, base=Node)]
394373
pub struct ExportResource {
@@ -400,12 +379,6 @@ pub struct ExportResource {
400379
pub bar: Option<Gd<RenamedCustomResource>>,
401380
}
402381

403-
#[godot_api]
404-
impl ExportResource {}
405-
406-
#[godot_api]
407-
impl INode for ExportResource {}
408-
409382
#[itest]
410383
fn export_resource() {
411384
let class = ExportResource::alloc_gd();

itest/rust/src/object_tests/virtual_methods_test.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ struct VirtualMethodTest {
4444
integer: i32,
4545
}
4646

47-
#[godot_api]
48-
impl VirtualMethodTest {}
49-
5047
#[godot_api]
5148
impl IRefCounted for VirtualMethodTest {
5249
fn to_string(&self) -> GString {

itest/rust/src/register_tests/option_ffi_test.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,3 @@ struct OptionExportFfiTest {
103103
#[export]
104104
optional_export: Option<Gd<Node>>,
105105
}
106-
107-
#[godot_api]
108-
impl OptionExportFfiTest {}

itest/rust/src/register_tests/var_test.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,3 @@ struct WithInitDefaults {
2020
#[init(default = -42)]
2121
expr_int: i64,
2222
}
23-
24-
// TODO Remove once https://github.com/godot-rust/gdext/issues/187 is fixed
25-
#[godot_api]
26-
impl WithInitDefaults {}

0 commit comments

Comments
 (0)