From 6cb090345ece4a97c640159240594f3902e37032 Mon Sep 17 00:00:00 2001 From: unexge Date: Wed, 5 Aug 2020 13:25:26 +0300 Subject: Pattern match on slice elements instead of using `.first().unwrap()` --- crates/ra_assists/src/handlers/expand_glob_import.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'crates') diff --git a/crates/ra_assists/src/handlers/expand_glob_import.rs b/crates/ra_assists/src/handlers/expand_glob_import.rs index 978c6772e..69f6b3674 100644 --- a/crates/ra_assists/src/handlers/expand_glob_import.rs +++ b/crates/ra_assists/src/handlers/expand_glob_import.rs @@ -147,17 +147,16 @@ fn replace_ast( path: ast::Path, used_names: Vec, ) { - let replacement: Either = if used_names.len() == 1 { - Either::Left(ast::make::use_tree( - ast::make::path_from_text(&format!("{}::{}", path, used_names.first().unwrap())), + let replacement: Either = match used_names.as_slice() { + [name] => Either::Left(ast::make::use_tree( + ast::make::path_from_text(&format!("{}::{}", path, name)), None, None, false, - )) - } else { - Either::Right(ast::make::use_tree_list(used_names.iter().map(|n| { + )), + names => Either::Right(ast::make::use_tree_list(names.iter().map(|n| { ast::make::use_tree(ast::make::path_from_text(&n.to_string()), None, None, false) - }))) + }))), }; let mut replace_node = |replacement: Either| { -- cgit v1.2.3