Skip to content

Unqualify method call adds trait import even if not necessary #19912

@svix-jplatte

Description

@svix-jplatte

Given something like

enum Error {
    Foo(foo::Error),
    Bar(bar::Error),
}

impl std::error::Error for Error {
    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
        match self {
            Self::Foo(e) => std::error::Error::source(e),
            Self::Bar(e) => std::error::Error::source(e),
        }
    }
}

one might want to un-qualify std::error::Error::source. However, using the "unqualify method call" assist adds an import of std::error::Error, which is not necessary because methods from traits are always in scope within an impl for that trait, and in this case even results in an error because the name Error is already defined in the module.

rust-analyzer version: 0.4.2483-standalone
rustc version: 1.89.0-nightly (414482f6a 2025-05-13)
editor or extension: VSCode 0.4.2483 (pre-release, from OpenVSX)

@rustbot label +A-assists

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions