@@ -129,32 +129,15 @@ pub(crate) fn convert_to_guarded_return(acc: &mut Assists, ctx: &AssistContext<'
129
129
}
130
130
Some ( ( path, bound_ident) ) => {
131
131
// If-let.
132
- let match_expr = {
133
- let happy_arm = {
134
- let pat = make:: tuple_struct_pat (
135
- path,
136
- once ( make:: ext:: simple_ident_pat ( make:: name ( "it" ) ) . into ( ) ) ,
137
- ) ;
138
- let expr = {
139
- let path = make:: ext:: ident_path ( "it" ) ;
140
- make:: expr_path ( path)
141
- } ;
142
- make:: match_arm ( once ( pat. into ( ) ) , None , expr)
143
- } ;
144
-
145
- let sad_arm = make:: match_arm (
146
- // FIXME: would be cool to use `None` or `Err(_)` if appropriate
147
- once ( make:: wildcard_pat ( ) . into ( ) ) ,
148
- None ,
149
- early_expression,
150
- ) ;
151
-
152
- make:: expr_match ( cond_expr, make:: match_arm_list ( vec ! [ happy_arm, sad_arm] ) )
153
- } ;
154
-
155
- let let_stmt = make:: let_stmt ( bound_ident, None , Some ( match_expr) ) ;
156
- let let_stmt = let_stmt. indent ( if_indent_level) ;
157
- let_stmt. syntax ( ) . clone_for_update ( )
132
+ let pat = make:: tuple_struct_pat ( path, once ( bound_ident) ) ;
133
+ let let_else_stmt = make:: let_else_stmt (
134
+ pat. into ( ) ,
135
+ None ,
136
+ cond_expr,
137
+ ast:: make:: tail_only_block_expr ( early_expression) ,
138
+ ) ;
139
+ let let_else_stmt = let_else_stmt. indent ( if_indent_level) ;
140
+ let_else_stmt. syntax ( ) . clone_for_update ( )
158
141
}
159
142
} ;
160
143
@@ -238,10 +221,7 @@ fn main(n: Option<String>) {
238
221
r#"
239
222
fn main(n: Option<String>) {
240
223
bar();
241
- let n = match n {
242
- Some(it) => it,
243
- _ => return,
244
- };
224
+ let Some(n) = n else { return };
245
225
foo(n);
246
226
247
227
// comment
@@ -264,10 +244,7 @@ fn main() {
264
244
"# ,
265
245
r#"
266
246
fn main() {
267
- let x = match Err(92) {
268
- Ok(it) => it,
269
- _ => return,
270
- };
247
+ let Ok(x) = Err(92) else { return };
271
248
foo(x);
272
249
}
273
250
"# ,
@@ -292,10 +269,7 @@ fn main(n: Option<String>) {
292
269
r#"
293
270
fn main(n: Option<String>) {
294
271
bar();
295
- let n = match n {
296
- Some(it) => it,
297
- _ => return,
298
- };
272
+ let Some(n) = n else { return };
299
273
foo(n);
300
274
301
275
// comment
@@ -323,10 +297,7 @@ fn main(n: Option<String>) {
323
297
r#"
324
298
fn main(n: Option<String>) {
325
299
bar();
326
- let mut n = match n {
327
- Some(it) => it,
328
- _ => return,
329
- };
300
+ let Some(mut n) = n else { return };
330
301
foo(n);
331
302
332
303
// comment
@@ -354,10 +325,7 @@ fn main(n: Option<&str>) {
354
325
r#"
355
326
fn main(n: Option<&str>) {
356
327
bar();
357
- let ref n = match n {
358
- Some(it) => it,
359
- _ => return,
360
- };
328
+ let Some(ref n) = n else { return };
361
329
foo(n);
362
330
363
331
// comment
@@ -412,10 +380,7 @@ fn main() {
412
380
r#"
413
381
fn main() {
414
382
while true {
415
- let n = match n {
416
- Some(it) => it,
417
- _ => continue,
418
- };
383
+ let Some(n) = n else { continue };
419
384
foo(n);
420
385
bar();
421
386
}
@@ -469,10 +434,7 @@ fn main() {
469
434
r#"
470
435
fn main() {
471
436
loop {
472
- let n = match n {
473
- Some(it) => it,
474
- _ => continue,
475
- };
437
+ let Some(n) = n else { continue };
476
438
foo(n);
477
439
bar();
478
440
}
0 commit comments