Skip to content

"Remove all unused imports" code action incorrectly removes as aliased imports. #18129

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

Closed
msix29 opened this issue Sep 17, 2024 · 2 comments · Fixed by #18164
Closed

"Remove all unused imports" code action incorrectly removes as aliased imports. #18129

msix29 opened this issue Sep 17, 2024 · 2 comments · Fixed by #18164
Labels
A-assists C-bug Category: bug

Comments

@msix29
Copy link

msix29 commented Sep 17, 2024

rust-analyzer version: 0.3.2112-standalone

rustc version: rustc 1.80.1 (3f5fd8dd4 2024-08-06)

editor or extension: VScode - latest version (seems to be v0.3.2112)

relevant settings: None

repository link (if public, optional): Irrelevant

code snippet to reproduce:

// Any aliased import would really work.

use std::io::Error as IoError; // Here (read after code snippet)

fn main() -> Result<(), IoError> { // Any usage of the alias (it's now clearly used).
    Ok(())
}

Place your cursor at the marked spot in the code, click ctrl + . (or your keybind for code actions) and select "Remove all the unused imports".

@msix29 msix29 added the C-bug Category: bug label Sep 17, 2024
@msix29
Copy link
Author

msix29 commented Sep 17, 2024

An extra note: If there are some actual unused imports, the same behaviour doesn't happen. The code action with this code would work as expected:

use std::{fs, io::Error as IoError};

fn main() -> Result<(), IoError> {
    Ok(())
}

@msix29
Copy link
Author

msix29 commented Sep 17, 2024

An extra note (again), seems like adding self does cause the wrong behaviour. This wouldn't work correctly:

use std::{self, io::Error as IoError};

fn main() -> Result<(), IoError> {
    Ok(())
}

This is... odd? Importing anything but self doesn't cause the same (wrong) behaviour. Also, in the code above, it would just remove the whole use statement.

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
2 participants