aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorunexge <[email protected]>2020-08-05 11:25:26 +0100
committerunexge <[email protected]>2020-08-05 11:25:26 +0100
commit6cb090345ece4a97c640159240594f3902e37032 (patch)
tree4903d26fb47e8cb2f45fc9b6b8e67db166685507 /crates
parent5214b4cdba2c4976cb1ca4724a008268cdaf3e61 (diff)
Pattern match on slice elements instead of using `.first().unwrap()`
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_assists/src/handlers/expand_glob_import.rs13
1 files changed, 6 insertions, 7 deletions
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(
147 path: ast::Path, 147 path: ast::Path,
148 used_names: Vec<Name>, 148 used_names: Vec<Name>,
149) { 149) {
150 let replacement: Either<ast::UseTree, ast::UseTreeList> = if used_names.len() == 1 { 150 let replacement: Either<ast::UseTree, ast::UseTreeList> = match used_names.as_slice() {
151 Either::Left(ast::make::use_tree( 151 [name] => Either::Left(ast::make::use_tree(
152 ast::make::path_from_text(&format!("{}::{}", path, used_names.first().unwrap())), 152 ast::make::path_from_text(&format!("{}::{}", path, name)),
153 None, 153 None,
154 None, 154 None,
155 false, 155 false,
156 )) 156 )),
157 } else { 157 names => Either::Right(ast::make::use_tree_list(names.iter().map(|n| {
158 Either::Right(ast::make::use_tree_list(used_names.iter().map(|n| {
159 ast::make::use_tree(ast::make::path_from_text(&n.to_string()), None, None, false) 158 ast::make::use_tree(ast::make::path_from_text(&n.to_string()), None, None, false)
160 }))) 159 }))),
161 }; 160 };
162 161
163 let mut replace_node = |replacement: Either<ast::UseTree, ast::UseTreeList>| { 162 let mut replace_node = |replacement: Either<ast::UseTree, ast::UseTreeList>| {