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

Feature request: split trait

Open bluebear94 opened this issue 3 years ago • 0 comments

Let’s say I have a trait such as

trait T {
    pub fn foo(&self, a: i32) -> bool;
    pub fn bar<A>(&self, a: A, b: A) -> A;
    pub fn baz(&self) -> &'static str;
}

I want to split T into two traits: T1 (containing foo and bar) and T2 (containing baz). My suggested action would do the following:

  • Prompt for which items to assign to T1 and which to assign to T2
  • Create these traits
  • Optionally retain T as a subtrait of T1 + T2 with a blanket implementation
  • Refine trait bounds of the type A: T to A: T1 or A: T2 if they use items from only one of them
  • Split all implementations of T as well

The opposite action (merging two traits) could be added as well, although I don’t know how useful it would be in practice.

bluebear94 avatar Sep 04 '22 17:09 bluebear94