godot-rust / gdnative

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

`Ref::upcast` should not require `SafeAsRaw` #1040

Open chitoyuu opened 1 year ago

chitoyuu commented 1 year ago

From DragonAxe via Discord:

So I thought I would try using Ref instead of Instance, but I'm running into this error:

   #[method]
   fn _ready(&self, #[base] owner: TRef<Label>) {
       CLIENT_STORE.with(|store| {
           let a = owner.claim().upcast::<Node>();
           store.my_sig.subscribe(a);
       });
   }
error[E0599]: the method `upcast` exists for struct `gdnative::prelude::Ref<Label>`, but its trait > bounds were not satisfied
   --> src/controls/connection_status_label.rs:21:35
    |
21  |             let a = owner.claim().upcast::<Node>();
    |                                   ^^^^^^ method cannot be called on `gdnative::prelude::Ref<Label>` due to unsatisfied trait bounds
    |
   ::: /home/dragonaxe/.cargo/registry/src/github.com-1ecc6299db9ec823/gdnative-core-0.11.2/src/object/bounds.rs:237:1
    |
237 | pub struct RefImplBound {
    | ----------------------- doesn't satisfy `RefImplBound: SafeAsRaw<ManuallyManaged, Shared>`
    |
    = note: the following trait bounds were not satisfied:
            `RefImplBound: SafeAsRaw<ManuallyManaged, Shared>`

Ref::upcast shouldn't require SafeAsRaw since it is statically determined and doesn't perform that action.