godot-rust / gdnative

Rust bindings for Godot 3
https://godot-rust.github.io
MIT License
3.61k stars 210 forks source link

Better errors when the signature of exported methods are invalid #439

Closed ghost closed 1 year ago

ghost commented 4 years ago

Currently, all errors originating from the signatures of exported methods are spanned at the #[gdnative::methods] attribute. This makes it tricky to find the errors in cases where:

Currently, the errors look like:

error[E0308]: mismatched types
  --> examples/dodge_the_creeps/src/hud.rs:11:1
   |
11 | #[methods]
   | ^^^^^^^^^^ expected struct `gdnative::gdnative_bindings::CanvasLayer`, found `&gdnative::gdnative_bindings::CanvasLayer`
   |
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `gdnative::gdnative_bindings::PhysicsBody2D: gdnative::FromVariant` is not satisfied
  --> examples/dodge_the_creeps/src/player.rs:17:1
   |
17 | #[methods]
   | ^^^^^^^^^^ the trait `gdnative::FromVariant` is not implemented for `gdnative::gdnative_bindings::PhysicsBody2D`
   |
   = note: required by `gdnative::FromVariant::from_variant`
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

We might have to reimplement godot_wrap_method as procedural macro for the errors to be properly spanned.

ghost commented 4 years ago

This is partially improved in #443 and the errors point at individual method names now. It's still not ideal, but is a big improvement over the original situation.