Skip to content

Commit

Permalink
Remove all places where empty #[godot_api] workaround was in use
Browse files Browse the repository at this point in the history
  • Loading branch information
Bromeon committed Nov 26, 2023
1 parent c61a1ba commit 560cdee
Show file tree
Hide file tree
Showing 11 changed files with 4 additions and 102 deletions.
9 changes: 4 additions & 5 deletions godot-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ mod gen;

#[doc(hidden)]
pub mod private {
// If someone forgets #[godot_api], this causes a compile error, rather than virtual functions not being called at runtime.
#[allow(non_camel_case_types)]
pub trait You_forgot_the_attribute__godot_api {}
pub use crate::property::Cannot_export_without_godot_api_impl;

use std::sync::{Arc, Mutex};

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

use crate::{log, sys};

// If someone forgets #[godot_api], this causes a compile error, rather than virtual functions not being called at runtime.
#[allow(non_camel_case_types)]
pub trait You_forgot_the_attribute__godot_api {}

sys::plugin_registry!(pub __GODOT_PLUGIN_REGISTRY: ClassPlugin);

pub(crate) fn iterate_plugins(mut visitor: impl FnMut(&ClassPlugin)) {
Expand Down
17 changes: 0 additions & 17 deletions godot-core/src/property.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,23 +106,6 @@ impl PropertyHintInfo {
}
}

/// To export properties to Godot, you must have an impl-block with the `#[godot_api]` attribute, even if
/// it is empty.
///
/// This trait is automatically implemented when such an impl-block is present. If Rust complains that it is
/// not implemented, then you can usually fix this by adding:
///
/// ```ignore
/// #[godot_api]
/// impl MyClass {}
/// ```
///
/// Where you replace `MyClass` with the name of your class.
#[allow(non_camel_case_types)]
pub trait Cannot_export_without_godot_api_impl {
const EXISTS: () = ();
}

/// Functions used to translate user-provided arguments into export hints.
pub mod export_info_functions {
use crate::builtin::GString;
Expand Down
10 changes: 0 additions & 10 deletions godot-macros/src/class/data_models/property.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,18 +203,8 @@ pub fn make_property_impl(class_name: &Ident, fields: &Fields) -> TokenStream {
});
}

let enforce_godot_api_impl = if !export_tokens.is_empty() {
quote! {
const MUST_HAVE_GODOT_API_IMPL: () = <#class_name as ::godot::private::Cannot_export_without_godot_api_impl>::EXISTS;
}
} else {
TokenStream::new()
};

quote! {
impl #class_name {
#enforce_godot_api_impl

#(#getter_setter_impls)*
}

Expand Down
2 changes: 0 additions & 2 deletions godot-macros/src/class/godot_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,6 @@ fn transform_inherent_impl(mut original_impl: Impl) -> Result<TokenStream, Error
}
}

impl ::godot::private::Cannot_export_without_godot_api_impl for #class_name {}

::godot::sys::plugin_add!(__GODOT_PLUGIN_REGISTRY in #prv; #prv::ClassPlugin {
class_name: #class_name_obj,
component: #prv::PluginComponent::UserMethodBinds {
Expand Down
22 changes: 0 additions & 22 deletions godot-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,18 +124,12 @@ use crate::util::ident;
/// #[var]
/// my_field: i64,
/// }
///
/// #[godot_api]
/// impl MyStruct {}
/// ```
///
/// This makes the field accessible in GDScript using `my_struct.my_field` syntax. Additionally, it
/// generates a trivial getter and setter named `get_my_field` and `set_my_field`, respectively.
/// These are `pub` in Rust, since they're exposed from GDScript anyway.
///
/// For technical reasons, an impl-block with the `#[godot_api]` attribute is required for properties to
/// work. Failing to include one will cause a compile error if you try to create any properties.
///
/// If you want to implement your own getter and/or setter, write those as a function on your Rust
/// type, expose it using `#[func]`, and annotate the field with
/// `#[export(get = ..., set = ...)]`:
Expand Down Expand Up @@ -196,9 +190,6 @@ use crate::util::ident;
/// #[export]
/// my_field: i64,
/// }
///
/// #[godot_api]
/// impl MyStruct {}
/// ```
///
/// If you dont also include a `#[var]` attribute, then a default one will be generated.
Expand Down Expand Up @@ -252,9 +243,6 @@ use crate::util::ident;
/// #[export(flags = (A = 1, B = 2, AB = 3))]
/// flags: u32,
/// }
///
/// #[godot_api]
/// impl MyStruct {}
/// ```
///
/// Most values in expressions like `key = value`, can be an arbitrary expression that evaluates to the
Expand All @@ -274,9 +262,6 @@ use crate::util::ident;
/// #[export(flags = (A = 0b0001, B = 0b0010, C = 0b0100, D = 0b1000))]
/// flags: u32,
/// }
///
/// #[godot_api]
/// impl MyStruct {}
/// ```
///
/// You can specify custom property hints, hint strings, and usage flags in a `#[var]` attribute using the
Expand All @@ -297,9 +282,6 @@ use crate::util::ident;
/// )]
/// my_field: i64,
/// }
///
/// #[godot_api]
/// impl MyStruct {}
/// ```
///
///
Expand Down Expand Up @@ -541,10 +523,6 @@ pub fn derive_from_godot(input: TokenStream) -> TokenStream {
/// foo: TestEnum
/// }
///
/// # //TODO: remove this when https://github.com/godot-rust/gdext/issues/187 is truly addressed
/// # #[godot_api]
/// # impl TestClass {}
///
/// # fn main() {
/// let mut class = TestClass {foo: TestEnum::B};
/// assert_eq!(class.get_foo(), TestEnum::B as i32);
Expand Down
3 changes: 0 additions & 3 deletions itest/rust/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,9 +457,6 @@ fn generate_property_template(inputs: &[Input]) -> PropertyTests {
#[export(enum = (Rebecca, Mary, Leah))]
export_enum_string_rebecca_mary_leah: GString,
}

#[godot_api]
impl PropertyTestsRust {}
};

let gdscript = format!(
Expand Down
6 changes: 0 additions & 6 deletions itest/rust/src/object_tests/object_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -844,19 +844,13 @@ pub mod object_test_gd {
i: i64,
}

#[godot_api]
impl MockObjRust {}

#[derive(GodotClass)]
#[class(init, base=RefCounted)]
struct MockRefCountedRust {
#[var]
i: i64,
}

#[godot_api]
impl MockRefCountedRust {}

#[derive(GodotClass, Debug)]
#[class(init, base=RefCounted)]
struct ObjectTest;
Expand Down
27 changes: 0 additions & 27 deletions itest/rust/src/object_tests/property_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,6 @@ struct CheckAllExports {
color_no_alpha: Color,
}

#[godot_api]
impl CheckAllExports {}

#[repr(i64)]
#[derive(Property, Export, Eq, PartialEq, Debug)]
pub enum TestEnum {
Expand All @@ -315,9 +312,6 @@ pub struct DeriveProperty {
pub foo: TestEnum,
}

#[godot_api]
impl DeriveProperty {}

#[itest]
fn derive_property() {
let mut class = DeriveProperty { foo: TestEnum::B };
Expand All @@ -335,9 +329,6 @@ pub struct DeriveExport {
pub base: Base<RefCounted>,
}

#[godot_api]
impl DeriveExport {}

#[godot_api]
impl IRefCounted for DeriveExport {
fn init(base: godot::obj::Base<Self::Base>) -> Self {
Expand Down Expand Up @@ -373,22 +364,10 @@ fn derive_export() {
#[class(init, base=Resource)]
pub struct CustomResource {}

#[godot_api]
impl CustomResource {}

#[godot_api]
impl IResource for CustomResource {}

#[derive(GodotClass)]
#[class(init, base=Resource, rename=NewNameCustomResource)]
pub struct RenamedCustomResource {}

#[godot_api]
impl RenamedCustomResource {}

#[godot_api]
impl IResource for RenamedCustomResource {}

#[derive(GodotClass)]
#[class(init, base=Node)]
pub struct ExportResource {
Expand All @@ -400,12 +379,6 @@ pub struct ExportResource {
pub bar: Option<Gd<RenamedCustomResource>>,
}

#[godot_api]
impl ExportResource {}

#[godot_api]
impl INode for ExportResource {}

#[itest]
fn export_resource() {
let class = ExportResource::alloc_gd();
Expand Down
3 changes: 0 additions & 3 deletions itest/rust/src/object_tests/virtual_methods_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ struct VirtualMethodTest {
integer: i32,
}

#[godot_api]
impl VirtualMethodTest {}

#[godot_api]
impl IRefCounted for VirtualMethodTest {
fn to_string(&self) -> GString {
Expand Down
3 changes: 0 additions & 3 deletions itest/rust/src/register_tests/option_ffi_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,3 @@ struct OptionExportFfiTest {
#[export]
optional_export: Option<Gd<Node>>,
}

#[godot_api]
impl OptionExportFfiTest {}
4 changes: 0 additions & 4 deletions itest/rust/src/register_tests/var_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,3 @@ struct WithInitDefaults {
#[init(default = -42)]
expr_int: i64,
}

// TODO Remove once https://github.com/godot-rust/gdext/issues/187 is fixed
#[godot_api]
impl WithInitDefaults {}

0 comments on commit 560cdee

Please sign in to comment.