mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-24 12:03:31 +00:00
Pattern match on slice elements instead of using .first().unwrap()
This commit is contained in:
parent
5214b4cdba
commit
6cb090345e
1 changed files with 6 additions and 7 deletions
|
@ -147,17 +147,16 @@ fn replace_ast(
|
||||||
path: ast::Path,
|
path: ast::Path,
|
||||||
used_names: Vec<Name>,
|
used_names: Vec<Name>,
|
||||||
) {
|
) {
|
||||||
let replacement: Either<ast::UseTree, ast::UseTreeList> = if used_names.len() == 1 {
|
let replacement: Either<ast::UseTree, ast::UseTreeList> = match used_names.as_slice() {
|
||||||
Either::Left(ast::make::use_tree(
|
[name] => Either::Left(ast::make::use_tree(
|
||||||
ast::make::path_from_text(&format!("{}::{}", path, used_names.first().unwrap())),
|
ast::make::path_from_text(&format!("{}::{}", path, name)),
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
false,
|
false,
|
||||||
))
|
)),
|
||||||
} else {
|
names => Either::Right(ast::make::use_tree_list(names.iter().map(|n| {
|
||||||
Either::Right(ast::make::use_tree_list(used_names.iter().map(|n| {
|
|
||||||
ast::make::use_tree(ast::make::path_from_text(&n.to_string()), None, None, false)
|
ast::make::use_tree(ast::make::path_from_text(&n.to_string()), None, None, false)
|
||||||
})))
|
}))),
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut replace_node = |replacement: Either<ast::UseTree, ast::UseTreeList>| {
|
let mut replace_node = |replacement: Either<ast::UseTree, ast::UseTreeList>| {
|
||||||
|
|
Loading…
Reference in a new issue