Skip to content

Inline function assist produces invalid code when inlining across generic impl blocks #19827

Open
@svix-jplatte

Description

@svix-jplatte

I hit this with a generic From impl, but it can be reduced to two inherent generic impls:

struct Generic<T>(T);

impl<T> Generic<T> {
    fn new() -> Self {
        // can also use Self::new2()
        Generic::new2()
    }
}

impl<T> Generic<T> {
    fn new2() -> Self {
        Self(todo!())
    }
}

inlining new2 currently changes the first impl block to:

impl<T> Generic<T> {
    fn new() -> Self {
        Generic<T>(todo!())
    }
}

but this is invalid syntax. Generic<T> in the function body should be one of

  • Self
  • Generic
  • Generic::<T>

rust-analyzer version: 0.4.2467-standalone
rustc version: 1.89.0-nightly (414482f6a 2025-05-13)
editor or extension: VSCode (ext version 0.4.2467)

@rustbot label +A-assists

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions