mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-29 10:13:54 +00:00
Simplify
This commit is contained in:
parent
71c002e589
commit
aaaa68b56c
@ -5,7 +5,6 @@ use crate::{
|
|||||||
utils::{find_insert_use_container, insert_use_statement},
|
utils::{find_insert_use_container, insert_use_statement},
|
||||||
AssistContext, AssistId, Assists,
|
AssistContext, AssistId, Assists,
|
||||||
};
|
};
|
||||||
use either::Either;
|
|
||||||
|
|
||||||
// Assist: replace_qualified_name_with_use
|
// Assist: replace_qualified_name_with_use
|
||||||
//
|
//
|
||||||
@ -56,14 +55,8 @@ pub(crate) fn replace_qualified_name_with_use(
|
|||||||
None => return,
|
None => return,
|
||||||
};
|
};
|
||||||
let mut rewriter = SyntaxRewriter::default();
|
let mut rewriter = SyntaxRewriter::default();
|
||||||
match container {
|
let syntax = container.either(|l| l.syntax().clone(), |r| r.syntax().clone());
|
||||||
Either::Left(l) => {
|
shorten_paths(&mut rewriter, syntax, hir_path.mod_path());
|
||||||
shorten_paths(&mut rewriter, l.syntax().clone(), hir_path.mod_path());
|
|
||||||
}
|
|
||||||
Either::Right(r) => {
|
|
||||||
shorten_paths(&mut rewriter, r.syntax().clone(), hir_path.mod_path());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
builder.rewrite(rewriter);
|
builder.rewrite(rewriter);
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@ -90,7 +83,7 @@ fn collect_hir_path_segments(path: &hir::Path) -> Option<Vec<SmolStr>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Adds replacements to `re` that shorten `path` in all descendants of `node`.
|
/// Adds replacements to `re` that shorten `path` in all descendants of `node`.
|
||||||
fn shorten_paths(re: &mut SyntaxRewriter<'static>, node: SyntaxNode, path: &ModPath) {
|
fn shorten_paths(rewriter: &mut SyntaxRewriter<'static>, node: SyntaxNode, path: &ModPath) {
|
||||||
for child in node.children() {
|
for child in node.children() {
|
||||||
match_ast! {
|
match_ast! {
|
||||||
match child {
|
match child {
|
||||||
@ -101,12 +94,12 @@ fn shorten_paths(re: &mut SyntaxRewriter<'static>, node: SyntaxNode, path: &ModP
|
|||||||
ast::Module(_it) => continue,
|
ast::Module(_it) => continue,
|
||||||
|
|
||||||
ast::Path(p) => {
|
ast::Path(p) => {
|
||||||
match maybe_replace_path(re, &p, path) {
|
match maybe_replace_path(rewriter, &p, path) {
|
||||||
Some(()) => {},
|
Some(()) => {},
|
||||||
None => shorten_paths(re, p.syntax().clone(), path),
|
None => shorten_paths(rewriter, p.syntax().clone(), path),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
_ => shorten_paths(re, child, path),
|
_ => shorten_paths(rewriter, child, path),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user