File tree Expand file tree Collapse file tree 3 files changed +48
-5
lines changed
ide-diagnostics/src/handlers Expand file tree Collapse file tree 3 files changed +48
-5
lines changed Original file line number Diff line number Diff line change @@ -1229,10 +1229,11 @@ impl InferenceContext<'_> {
1229
1229
self . select_from_expr ( * expr) ;
1230
1230
}
1231
1231
}
1232
- Expr :: Let { pat : _ , expr } => {
1232
+ Expr :: Let { pat, expr } => {
1233
1233
self . walk_expr ( * expr) ;
1234
- let place = self . place_of_expr ( * expr) ;
1235
- self . ref_expr ( * expr, place) ;
1234
+ if let Some ( place) = self . place_of_expr ( * expr) {
1235
+ self . consume_with_pat ( place, * pat) ;
1236
+ }
1236
1237
}
1237
1238
Expr :: UnaryOp { expr, op : _ }
1238
1239
| Expr :: Array ( Array :: Repeat { initializer : expr, repeat : _ } )
Original file line number Diff line number Diff line change @@ -446,20 +446,44 @@ fn main() {
446
446
}
447
447
448
448
#[ test]
449
- fn let_binding_is_a_ref_capture ( ) {
449
+ fn let_binding_is_a_ref_capture_in_ref_binding ( ) {
450
450
check_closure_captures (
451
451
r#"
452
452
//- minicore:copy
453
453
struct S;
454
454
fn main() {
455
455
let mut s = S;
456
456
let s_ref = &mut s;
457
+ let mut s2 = S;
458
+ let s_ref2 = &mut s2;
457
459
let closure = || {
458
460
if let ref cb = s_ref {
461
+ } else if let ref mut cb = s_ref2 {
459
462
}
460
463
};
461
464
}
462
465
"# ,
463
- expect ! [ "83..135;49..54;112..117 ByRef(Shared) s_ref &'? &'? mut S" ] ,
466
+ expect ! [ [ r#"
467
+ 129..225;49..54;149..155 ByRef(Shared) s_ref &'? &'? mut S
468
+ 129..225;93..99;188..198 ByRef(Mut { kind: Default }) s_ref2 &'? mut &'? mut S"# ] ] ,
469
+ ) ;
470
+ }
471
+
472
+ #[ test]
473
+ fn let_binding_is_a_value_capture_in_binding ( ) {
474
+ check_closure_captures (
475
+ r#"
476
+ //- minicore:copy, option
477
+ struct Box(i32);
478
+ fn main() {
479
+ let b = Some(Box(0));
480
+ let closure = || {
481
+ if let Some(b) = b {
482
+ let _move = b;
483
+ }
484
+ };
485
+ }
486
+ "# ,
487
+ expect ! [ "73..149;37..38;103..104 ByValue b Option<Box>" ] ,
464
488
) ;
465
489
}
Original file line number Diff line number Diff line change @@ -236,6 +236,24 @@ impl S {
236
236
};
237
237
}
238
238
}
239
+ "# ,
240
+ )
241
+ }
242
+
243
+ #[ test]
244
+ fn regression_20155 ( ) {
245
+ check_diagnostics (
246
+ r#"
247
+ //- minicore: copy, option
248
+ struct Box(i32);
249
+ fn test() {
250
+ let b = Some(Box(0));
251
+ || {
252
+ if let Some(b) = b {
253
+ let _move = b;
254
+ }
255
+ };
256
+ }
239
257
"# ,
240
258
)
241
259
}
You can’t perform that action at this time.
0 commit comments