@@ -9,7 +9,7 @@ use syntax::{
9
9
algo,
10
10
ast:: {
11
11
self , edit_in_place:: Removable , make, AstNode , HasAttrs , HasModuleItem , HasVisibility ,
12
- PathSegmentKind , Rename , UseTree ,
12
+ PathSegmentKind , UseTree ,
13
13
} ,
14
14
ted, Direction , NodeOrToken , SyntaxKind , SyntaxNode ,
15
15
} ;
@@ -163,16 +163,12 @@ pub fn insert_use(scope: &ImportScope, path: ast::Path, cfg: &InsertUseConfig) {
163
163
pub fn insert_use_as_alias ( scope : & ImportScope , path : ast:: Path , cfg : & InsertUseConfig ) {
164
164
let text: & str = "use foo as _" ;
165
165
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`" ) ;
176
172
let alias = node. rename ( ) ;
177
173
178
174
insert_use_with_alias_option ( scope, path, cfg, alias) ;
@@ -202,11 +198,8 @@ fn insert_use_with_alias_option(
202
198
} ;
203
199
}
204
200
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 ( ) ;
210
203
211
204
// merge into existing imports if possible
212
205
if let Some ( mb) = mb {
0 commit comments