Skip to content

Commit 0dcce73

Browse files
committed
force move(expr) captures to ByValue
1 parent 9953aa0 commit 0dcce73

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

compiler/rustc_hir_typeck/src/upvar.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,22 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
210210

211211
let _ = euv::ExprUseVisitor::new(&closure_fcx, &mut delegate).consume_body(body);
212212

213+
let explicit_captures = match self.tcx.hir_node(closure_hir_id).expect_expr().kind {
214+
hir::ExprKind::Closure(closure) => closure.explicit_captures,
215+
_ => bug!("expected closure expr for {:?}", closure_hir_id),
216+
};
217+
for capture in explicit_captures {
218+
let place = closure_fcx.place_for_root_variable(closure_def_id, capture.var_hir_id);
219+
delegate.capture_information.push((
220+
place,
221+
ty::CaptureInfo {
222+
capture_kind_expr_id: Some(capture.var_hir_id),
223+
path_expr_id: Some(capture.var_hir_id),
224+
capture_kind: UpvarCapture::ByValue,
225+
},
226+
));
227+
}
228+
213229
// There are several curious situations with coroutine-closures where
214230
// analysis is too aggressive with borrows when the coroutine-closure is
215231
// marked `move`. Specifically:

0 commit comments

Comments
 (0)