Skip to content

Auto completion of async fn xxxx for desugared async fn in trait form #17719

Closed
@hyf0

Description

@hyf0

Hi. I'm thinking about improving the dx of writing impl DesugaredAsyncTrait for Foo. So far the rust analyzer will only infer auto completion like

image

However, I found that the compiler will allow the following code compiles. If this is an expected behavior(It's expected, see the following zulipchat link), maybe it's ok to make rust analyzer to support auto completion that starts with async fn foo( the sugar version rather than only desugared version like now) for DesugaredAsyncTrait .

This will surely improve the dx of writing impl DesugaredAsyncTrait for XXX greatly without the need to write impl Future<Output=XXXX> + Send over and over again(Though there are also auto completed by the rust-analyzer :).

use std::future::Future;

trait DesugaredAsyncTrait {
    fn foo(&self) -> impl Future<Output = usize> + Send;
    fn bar(&self) -> impl Future<Output = usize> + Send;
}

struct Foo;

impl DesugaredAsyncTrait for Foo {
    fn foo(&self) -> impl Future<Output = usize> + Send {
        async { 1 }
    }

    //
    async fn bar(&self) -> usize {
        1
    }
}

fn main() {
    let fut = Foo.bar();
    fn _assert_send<T: Send>(_: T) {}
    _assert_send(fut);
}

Related:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions