File tree Expand file tree Collapse file tree 3 files changed +43
-1
lines changed
src/tools/rust-analyzer/crates
ide-diagnostics/src/handlers Expand file tree Collapse file tree 3 files changed +43
-1
lines changed Original file line number Diff line number Diff line change @@ -1230,11 +1230,15 @@ impl InferenceContext<'_> {
1230
1230
self . select_from_expr ( * expr) ;
1231
1231
}
1232
1232
}
1233
+ Expr :: Let { pat : _, expr } => {
1234
+ self . walk_expr ( * expr) ;
1235
+ let place = self . place_of_expr ( * expr) ;
1236
+ self . ref_expr ( * expr, place) ;
1237
+ }
1233
1238
Expr :: UnaryOp { expr, op : _ }
1234
1239
| Expr :: Array ( Array :: Repeat { initializer : expr, repeat : _ } )
1235
1240
| Expr :: Await { expr }
1236
1241
| Expr :: Loop { body : expr, label : _ }
1237
- | Expr :: Let { pat : _, expr }
1238
1242
| Expr :: Box { expr }
1239
1243
| Expr :: Cast { expr, type_ref : _ } => {
1240
1244
self . consume_expr ( * expr) ;
Original file line number Diff line number Diff line change @@ -444,3 +444,22 @@ fn main() {
444
444
expect ! [ "99..165;49..54;120..121,133..134 ByRef(Mut { kind: Default }) a &'? mut A" ] ,
445
445
) ;
446
446
}
447
+
448
+ #[ test]
449
+ fn let_binding_is_a_ref_capture ( ) {
450
+ check_closure_captures (
451
+ r#"
452
+ //- minicore:copy
453
+ struct S;
454
+ fn main() {
455
+ let mut s = S;
456
+ let s_ref = &mut s;
457
+ let closure = || {
458
+ if let ref cb = s_ref {
459
+ }
460
+ };
461
+ }
462
+ "# ,
463
+ expect ! [ "83..135;49..54;112..117 ByRef(Shared) s_ref &'? &'? mut S" ] ,
464
+ ) ;
465
+ }
Original file line number Diff line number Diff line change @@ -220,4 +220,23 @@ fn test() {
220
220
"# ,
221
221
)
222
222
}
223
+
224
+ #[ test]
225
+ fn regression_18201 ( ) {
226
+ check_diagnostics (
227
+ r#"
228
+ //- minicore: copy
229
+ struct NotCopy;
230
+ struct S(NotCopy);
231
+ impl S {
232
+ fn f(&mut self) {
233
+ || {
234
+ if let ref mut _cb = self.0 {
235
+ }
236
+ };
237
+ }
238
+ }
239
+ "# ,
240
+ )
241
+ }
223
242
}
You can’t perform that action at this time.
0 commit comments