#923·shuttle

[Bug]: Rust-analyzer's "implement missing members" for ResourceBuilder creates over-complicated code

Author: morlinbrotCreated May 16, 2023Updated Mar 12, 2025
LabelsS-Not Planned

What happened?

Rust analyzer provides the handy feature of automatically implementing missing members of a trait. When doing this for ResourceBuilder, it will generate function signatures that are more complicated than actually needed. Example:

rust
impl ResourceBuilder<MyResource> for MyResourceBuilder {
    // other stuff

    fn output<'life0, 'async_trait>(
        self,
        factory: &'life0 mut dyn shuttle_service::Factory,
    ) -> core::pin::Pin<
        Box<
            dyn core::future::Future<Output = Result<Self::Output, shuttle_service::Error>>
                + core::marker::Send
                + 'async_trait,
        >,
    >
    where
        'life0: 'async_trait,
        Self: 'async_trait,
    {
        todo!()
    }

    fn build<'life0, 'async_trait>(
        build_data: &'life0 Self::Output,
    ) -> core::pin::Pin<
        Box<
            dyn core::future::Future<Output = Result<SQLiteInstance, shuttle_service::Error>>
                + core::marker::Send
                + 'async_trait,
        >,
    >
    where
        'life0: 'async_trait,
        Self: 'async_trait,
    {
        todo!()
    }
}

This is due to the trait requiring async functions and async traits not yet being supported natively by Rust (The above is the actual representation of the trait in "pure" Rust as of now).

For an actual implementation, we're using the [async_trait] crate and the actual function signatures looking like so:

rust
#[async_trait]
impl ResourceBuilder<MyResource> for MyResourceBuilder {
    // other stuff

    async fn output(self, factory: &mut dyn Factory) -> Result<Self::Output, shuttle_service::Error> {
        todo!()
    }

    /// Build this resource from its config output
    async fn build(build_data: &Self::Output) -> Result<MyResource, shuttle_service::Error> {
        todo!()
    }
}

Also see the example in the docs for a copy-pasteable example.

I don't think there's a solution to this right now but this may help somebody coming across this issue and finding the issue here. It may also be worth adding an explanation one-liner to the docs on this, let me know if I should do that.

Version

v0.15.0

Which operating systems are you seeing the problem on?

macOS

Which CPU architectures are you seeing the problem on?

ARM64

Relevant log output

No response

Duplicate declaration

  • I have searched the issues and there are none like this.