Skip to content

Commit 6cb0903

Browse files
committed
Pattern match on slice elements instead of using .first().unwrap()
1 parent 5214b4c commit 6cb0903

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

crates/ra_assists/src/handlers/expand_glob_import.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,17 +147,16 @@ fn replace_ast(
147147
path: ast::Path,
148148
used_names: Vec<Name>,
149149
) {
150-
let replacement: Either<ast::UseTree, ast::UseTreeList> = if used_names.len() == 1 {
151-
Either::Left(ast::make::use_tree(
152-
ast::make::path_from_text(&format!("{}::{}", path, used_names.first().unwrap())),
150+
let replacement: Either<ast::UseTree, ast::UseTreeList> = match used_names.as_slice() {
151+
[name] => Either::Left(ast::make::use_tree(
152+
ast::make::path_from_text(&format!("{}::{}", path, name)),
153153
None,
154154
None,
155155
false,
156-
))
157-
} else {
158-
Either::Right(ast::make::use_tree_list(used_names.iter().map(|n| {
156+
)),
157+
names => Either::Right(ast::make::use_tree_list(names.iter().map(|n| {
159158
ast::make::use_tree(ast::make::path_from_text(&n.to_string()), None, None, false)
160-
})))
159+
}))),
161160
};
162161

163162
let mut replace_node = |replacement: Either<ast::UseTree, ast::UseTreeList>| {

0 commit comments

Comments
 (0)