rune-rs / rune

An embeddable dynamic programming language for Rust.
https://rune-rs.github.io
Apache License 2.0
1.7k stars 85 forks source link

Can not use vm_result on function taking `&mut self` #752

Open VorpalBlade opened 1 month ago

VorpalBlade commented 1 month ago

The following function:

    #[rune::function(vm_result, instance)]
    fn stdin(&mut self) -> Option<ChildStdin> {
        let inner = match &mut self.inner {
            Some(inner) => inner,
            None => {
                rune::vm_panic!("already completed");
            }
        };
        let stdin = inner.stdin.take()?;
        Some(ChildStdin { inner: stdin })
    }

gives the following error:

error[E0308]: mismatched types
   --> crates/konfigkoll_script/src/plugins/process.rs:176:17
    |
176 |                 rune::vm_panic!("already completed");
    |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Option<ChildStdout>`, found `VmResult<_>`
    |
    = note: expected enum `std::option::Option<plugins::process::ChildStdout>`
               found enum `VmResult<_>`
    = note: this error originates in the macro `rune::vm_panic` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0308]: mismatched types
   --> crates/konfigkoll_script/src/plugins/process.rs:191:17
    |
191 |                 rune::vm_panic!("already completed");
    |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Option<ChildStderr>`, found `VmResult<_>`
    |
    = note: expected enum `std::option::Option<plugins::process::ChildStderr>`
               found enum `VmResult<_>`
    = note: this error originates in the macro `rune::vm_panic` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0308`.
error: could not compile `konfigkoll_script` (lib) due to 4 previous errors

Removing the vm_result and the vm_panic makes it compile.

This is the latest on the 0.13 branch