Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

where Self: Sized exclusion not working with trait_variant support #55

Closed
ComputerDruid opened this issue Feb 17, 2025 · 0 comments · Fixed by #56
Closed

where Self: Sized exclusion not working with trait_variant support #55

ComputerDruid opened this issue Feb 17, 2025 · 0 comments · Fixed by #56

Comments

@ComputerDruid
Copy link

Using cargo script for brevity:

#!/usr/bin/env -S cargo +nightly -Zscript
---cargo
[package]
edition = "2021"
[dependencies]
dynosaur = "0.1.3"
trait-variant = "0.1.2"
---

#[trait_variant::make(Run: Send)]
#[dynosaur::dynosaur(DynLocalRun = dyn LocalRun)]
#[dynosaur::dynosaur(DynRun = dyn Run)]
pub trait LocalRun {
    async fn new() -> std::io::Result<Self>
    where
        Self: Sized;

    async fn run(&mut self) -> std::io::Result<()>;
}

fn main(){}

Gives compile error:

error[E0277]: `()` is not a future
  --> /home/cdruid/.cargo/target/e4/57393f8231c91d/script.rs:11:1
   |
11 | #[trait_variant::make(Run: Send)]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `()` is not a future
   |
   = help: the trait `Future` is not implemented for `()`

Peeking at the expansion, it looks like it's coming from:

impl<'dynosaur_struct> Run for DynRun<'dynosaur_struct> {
    fn new()
        ->
            impl ::core::future::Future<Output = std::io::Result<Self>> +
            Send where Self: Sized {
        ::core::panicking::panic("internal error: entered unreachable code")
    }

I think the typical workarounds here are either to use async fn new() (currently used for the !Send case) or let fut: ::core::pin::Pin<Box<dyn ::core::future::Future<Output = std::io::Result<Self>> + 'static + Send>> = panic!(); fut (which I believe was used in the original implementation)

@ComputerDruid ComputerDruid changed the title where Self:Sized exclusion not working with trait_variant support where Self: Sized exclusion not working with trait_variant support Feb 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant