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
handle {self} when removing unused imports #17140
base: master
Are you sure you want to change the base?
Conversation
c298bd6
to
7163d60
Compare
That transform is generally not valid, Now there is still a bug here in that we produce malformed syntax but we need to keep the braces. |
crates/syntax/src/ast/node_ext.rs
Outdated
@@ -376,11 +376,24 @@ impl ast::UseTreeList { | |||
.filter_map(|it| it.into_token().filter(|it| it.kind() == T![,])) | |||
} | |||
|
|||
pub fn is_just_self(&self) -> bool { | |||
if let Some((single_subtree,)) = self.use_trees().collect_tuple() { | |||
fn path_is_self(path: &ast::Path) -> bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be a closure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked to make this into a closure, and in the process decided to check the number of use_tree children as part of the same check (so now the closure is called has_single_subtree_that_is_not_self
)
7163d60
to
415e357
Compare
Yep. I have removed the second commit, the first commit (which fixes |
Before this commit `UseTree::remove_unnecessary_braces` removed the braces around `{self}` in `use x::y::{self};` but `use x::y::self;` is not valid rust.
415e357
to
a653ddf
Compare
The normalize import IDE assist (https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/normalize_import.rs) does transform #[test]
fn test_collapses_self() {
check_assist_variations!("std::fmt::{self}", "std::fmt");
} Is that a bug? |
Fixes #17139
On master
becomes
with this fix it instead becomes