Skip to content

Conversation

@A4-Tacks
Copy link
Member

Example

trait Foo {
    fn f(&self) -> i32;

    fn foo(&self) -> i32 {
        $0self.f()+self.f()$0
    }
}

Before this PR:

trait Foo {
    fn f(&self) -> i32;

    fn foo(&self) -> i32 {
        self.fun_name()
    }
}

fn $0fun_name(&self) -> i32 {
    self.f()+self.f()
}

After this PR:

trait Foo {
    fn f(&self) -> i32;

    fn foo(&self) -> i32 {
        self.fun_name()
    }

    fn $0fun_name(&self) -> i32 {
        self.f()+self.f()
    }
}

Example
---
```rust
trait Foo {
    fn f(&self) -> i32;

    fn foo(&self) -> i32 {
        $0self.f()+self.f()$0
    }
}
```

**Before this PR**:

```rust
trait Foo {
    fn f(&self) -> i32;

    fn foo(&self) -> i32 {
        self.fun_name()
    }
}

fn $0fun_name(&self) -> i32 {
    self.f()+self.f()
}
```

**After this PR**:

```rust
trait Foo {
    fn f(&self) -> i32;

    fn foo(&self) -> i32 {
        self.fun_name()
    }

    fn $0fun_name(&self) -> i32 {
        self.f()+self.f()
    }
}
```
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 19, 2025
@flodiebold
Copy link
Member

I'm not sure adding the method to the trait is usually going to be what the user wants?

@A4-Tacks
Copy link
Member Author

A4-Tacks commented Oct 19, 2025

I'm not sure adding the method to the trait is usually going to be what the user wants?

But it may be appropriate to do so instead of creating a generic function with all trait bounds and trait generic parameters

@Veykril
Copy link
Member

Veykril commented Oct 26, 2025

I think in this case, when the selection contains self locals, we might want to offer both extract to function and extract to trait method? I do agree we can't assume that the user wants a trait function in this case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants