rust-lang / rust-lang/rust-analyzer

Feature request: split trait

Open
#13,188 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No implementation files, tests, or entry points are named in the issue. Begin by locating the trait-related refactoring entry point and its tests, then verify the requested trait creation, optional subtrait retention, bound refinement, and implementation splitting against the examples described.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.