Skip to content

Assist "Generate method" selects current impl block even if it's a trait impl block #22123

@mrnossiom

Description

@mrnossiom

"Generate method" assist adds the code to the current impl even if this is a trait implementation.

I believe this is related to #21684 fixing #21550

rust-analyzer version: rust-analyzer 1.95.0 (5980761 2026-04-14)
rustc version: rustc 1.95.0 (59807616e 2026-04-14)

code snippet to reproduce:

trait Foo {
	fn foo();
}

struct Bar;

impl Bar {
	fn func1() {}

    // (3)
}

impl Foo for Bar {
	fn foo(&self) {
		self.func2(); // (1)
	}

    // (2)
}

Using the "Generate func2 method" assist at (1) adds the func2 method skeleton at (2) in the trait implementation block whereas I would expect it to default to (3) in the Bar struct block implementation.

cc @akashchakrabortymsc-cmd

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bug

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions