rust-analyzer icon indicating copy to clipboard operation
rust-analyzer copied to clipboard

Add ide-assist: generate blanket trait impl

Open A4-Tacks opened this issue 8 months ago • 3 comments

Close rust-lang/rust-analyzer#19768

This is very convenient for extending traits such as Iterator


Assist: generate_blanket_trait_impl

Generate blanket trait implementation.

trait $0Foo<T: Send>: ToOwned
where
    Self::Owned: Default,
{
    fn foo(&self) -> T;

    fn print_foo(&self) {
        println!("{}", self.foo());
    }
}

->

trait Foo<T: Send>: ToOwned
where
    Self::Owned: Default,
{
    fn foo(&self) -> T;

    fn print_foo(&self) {
        println!("{}", self.foo());
    }
}

$0impl<T: Send, This: ToOwned> Foo<T> for This
where
    Self::Owned: Default,
{
    fn foo(&self) -> T {
        todo!()
    }
}

A4-Tacks avatar May 09 '25 13:05 A4-Tacks

The indentation still seems to have some minor issues

A4-Tacks avatar May 12 '25 09:05 A4-Tacks

@Veykril May I ask if these PRs can be merged?

A4-Tacks avatar May 18 '25 11:05 A4-Tacks

r? @Veykril

A4-Tacks avatar May 25 '25 12:05 A4-Tacks

r? @ShoyuVanilla

A4-Tacks avatar Jul 17 '25 22:07 A4-Tacks

:warning: Warning :warning:

  • The following commits have merge commits (commits with multiple parents) in your changes. We have a no merge policy so these commits will need to be removed for this pull request to be merged.

    • b0cf5ee0ef2fda1e29401b2f44a670e9f3e55cfc

    You can start a rebase with the following commands:

    $ # rebase
    $ git pull --rebase https://github.com/rust-lang/rust-analyzer.git master
    $ git push --force-with-lease
    

rustbot avatar Jul 23 '25 23:07 rustbot

I think this overlaps with #19938? Though this adds blanket impls but I think they share lots of codes and we could reduce duplicates

ShoyuVanilla avatar Jul 25 '25 04:07 ShoyuVanilla

I think this overlaps with #19938? Though this adds blanket impls but I think they share lots of codes and we could reduce duplicates

I compared the differences between these two and it doesn't seem like there's much shared code

A4-Tacks avatar Jul 25 '25 05:07 A4-Tacks

Okay, I'll look into this more but it might take some time as I have other works for now 😅

ShoyuVanilla avatar Jul 25 '25 05:07 ShoyuVanilla

@ShoyuVanilla Do you have time to review this PR?

A4-Tacks avatar Oct 01 '25 11:10 A4-Tacks

Sorry, not yet (I've been sick these days 😅 ) I'll review this tomorrow.

ShoyuVanilla avatar Oct 01 '25 13:10 ShoyuVanilla

Okay, thank you for taking the time to review

A4-Tacks avatar Oct 01 '25 13:10 A4-Tacks