Skip to content

Commit 343eb47

Browse files
committed
Improve #[rpc] error message if Base<T> field is missing
1 parent 1d14ac2 commit 343eb47

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

godot-core/src/obj/traits.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ pub trait IndexEnum: EngineEnum {
244244
#[diagnostic::on_unimplemented(
245245
message = "Class `{Self}` requires a `Base<T>` field",
246246
label = "missing field `_base: Base<...>`",
247-
note = "A base field is required to access the base from within `self`, or when using script virtual functions",
247+
note = "A base field is required to access the base from within `self`, for script-virtual functions or #[rpc] methods",
248248
note = "see also: https://godot-rust.github.io/book/register/classes.html#the-base-field"
249249
)]
250250
pub trait WithBaseField: GodotClass + Bounds<Declarer = bounds::DeclUser> {

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ pub fn make_rpc_registrations_fn(class_name: &Ident, funcs: &[FuncDefinition]) -
7474
}
7575

7676
quote! {
77-
#[allow(clippy::needless_update)] // clippy complains about using `..RpcConfig::default()` if all fields are overridden
77+
// Clippy complains about using `..RpcConfig::default()` if all fields are overridden.
78+
#[allow(clippy::needless_update)]
7879
fn __register_rpcs(object: &mut dyn ::std::any::Any) {
7980
use ::std::any::Any;
8081
use ::godot::register::RpcConfig;
@@ -83,10 +84,12 @@ pub fn make_rpc_registrations_fn(class_name: &Ident, funcs: &[FuncDefinition]) -
8384
use ::godot::classes::Node;
8485
use ::godot::obj::{WithBaseField, Gd};
8586

86-
let mut gd = object
87-
.downcast_mut::<#class_name>()
88-
.expect("bad type erasure when registering RPCs")
89-
.to_gd();
87+
let this = object
88+
.downcast_ref::<#class_name>()
89+
.expect("bad type erasure when registering RPCs");
90+
91+
// Use fully-qualified syntax, so that error message isn't just "no method named `to_gd` found".
92+
let mut gd = ::godot::obj::WithBaseField::to_gd(this);
9093

9194
let node = gd.upcast_mut::<Node>();
9295
#( #rpc_registrations )*

0 commit comments

Comments
 (0)