Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
svix-jplatte opened this issue Jun 3, 2025 · 0 comments
Open

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

svix-jplatte opened this issue Jun 3, 2025 · 0 comments
Labels
A-assists C-bug Category: bug

Comments

@svix-jplatte
Copy link

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

@svix-jplatte svix-jplatte added the C-bug Category: bug label Jun 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-assists C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

2 participants