Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit a723acf

Browse files
committed
simplify the code
1 parent 4f5f7e2 commit a723acf

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

crates/ide-db/src/imports/insert_use.rs

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use syntax::{
99
algo,
1010
ast::{
1111
self, edit_in_place::Removable, make, AstNode, HasAttrs, HasModuleItem, HasVisibility,
12-
PathSegmentKind, Rename, UseTree,
12+
PathSegmentKind, UseTree,
1313
},
1414
ted, Direction, NodeOrToken, SyntaxKind, SyntaxNode,
1515
};
@@ -163,16 +163,12 @@ pub fn insert_use(scope: &ImportScope, path: ast::Path, cfg: &InsertUseConfig) {
163163
pub fn insert_use_as_alias(scope: &ImportScope, path: ast::Path, cfg: &InsertUseConfig) {
164164
let text: &str = "use foo as _";
165165
let parse = syntax::SourceFile::parse(text);
166-
let node = match parse.tree().syntax().descendants().find_map(UseTree::cast) {
167-
Some(it) => it,
168-
None => {
169-
panic!(
170-
"Failed to make ast node `{}` from text {}",
171-
std::any::type_name::<Rename>(),
172-
text
173-
)
174-
}
175-
};
166+
let node = parse
167+
.tree()
168+
.syntax()
169+
.descendants()
170+
.find_map(UseTree::cast)
171+
.expect("Failed to make ast node `Rename`");
176172
let alias = node.rename();
177173

178174
insert_use_with_alias_option(scope, path, cfg, alias);
@@ -202,11 +198,8 @@ fn insert_use_with_alias_option(
202198
};
203199
}
204200

205-
let use_item = if alias.is_some() {
206-
make::use_(None, make::use_tree(path.clone(), None, alias, false)).clone_for_update()
207-
} else {
208-
make::use_(None, make::use_tree(path.clone(), None, None, false)).clone_for_update()
209-
};
201+
let use_item =
202+
make::use_(None, make::use_tree(path.clone(), None, alias, false)).clone_for_update();
210203

211204
// merge into existing imports if possible
212205
if let Some(mb) = mb {

0 commit comments

Comments
 (0)