@@ -1129,6 +1129,7 @@ pub fn can_move_expr_to_closure_no_visit<'tcx>(
1129
1129
#[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
1130
1130
pub enum CaptureKind {
1131
1131
Value ,
1132
+ Use ,
1132
1133
Ref ( Mutability ) ,
1133
1134
}
1134
1135
impl CaptureKind {
@@ -1141,6 +1142,7 @@ impl std::ops::BitOr for CaptureKind {
1141
1142
fn bitor ( self , rhs : Self ) -> Self :: Output {
1142
1143
match ( self , rhs) {
1143
1144
( CaptureKind :: Value , _) | ( _, CaptureKind :: Value ) => CaptureKind :: Value ,
1145
+ ( CaptureKind :: Use , _) | ( _, CaptureKind :: Use ) => CaptureKind :: Use ,
1144
1146
( CaptureKind :: Ref ( Mutability :: Mut ) , CaptureKind :: Ref ( _) )
1145
1147
| ( CaptureKind :: Ref ( _) , CaptureKind :: Ref ( Mutability :: Mut ) ) => CaptureKind :: Ref ( Mutability :: Mut ) ,
1146
1148
( CaptureKind :: Ref ( Mutability :: Not ) , CaptureKind :: Ref ( Mutability :: Not ) ) => CaptureKind :: Ref ( Mutability :: Not ) ,
@@ -1220,7 +1222,7 @@ pub fn capture_local_usage(cx: &LateContext<'_>, e: &Expr<'_>) -> CaptureKind {
1220
1222
} ,
1221
1223
ExprKind :: Let ( let_expr) => {
1222
1224
let mutability = match pat_capture_kind ( cx, let_expr. pat ) {
1223
- CaptureKind :: Value => Mutability :: Not ,
1225
+ CaptureKind :: Value | CaptureKind :: Use => Mutability :: Not ,
1224
1226
CaptureKind :: Ref ( m) => m,
1225
1227
} ;
1226
1228
return CaptureKind :: Ref ( mutability) ;
@@ -1229,7 +1231,7 @@ pub fn capture_local_usage(cx: &LateContext<'_>, e: &Expr<'_>) -> CaptureKind {
1229
1231
let mut mutability = Mutability :: Not ;
1230
1232
for capture in arms. iter ( ) . map ( |arm| pat_capture_kind ( cx, arm. pat ) ) {
1231
1233
match capture {
1232
- CaptureKind :: Value => break ,
1234
+ CaptureKind :: Value | CaptureKind :: Use => break ,
1233
1235
CaptureKind :: Ref ( Mutability :: Mut ) => mutability = Mutability :: Mut ,
1234
1236
CaptureKind :: Ref ( Mutability :: Not ) => ( ) ,
1235
1237
}
@@ -1239,7 +1241,7 @@ pub fn capture_local_usage(cx: &LateContext<'_>, e: &Expr<'_>) -> CaptureKind {
1239
1241
_ => break ,
1240
1242
} ,
1241
1243
Node :: LetStmt ( l) => match pat_capture_kind ( cx, l. pat ) {
1242
- CaptureKind :: Value => break ,
1244
+ CaptureKind :: Value | CaptureKind :: Use => break ,
1243
1245
capture @ CaptureKind :: Ref ( _) => return capture,
1244
1246
} ,
1245
1247
_ => break ,
@@ -1294,6 +1296,7 @@ pub fn can_move_expr_to_closure<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'
1294
1296
if !self . locals . contains ( & local_id) {
1295
1297
let capture = match capture. info . capture_kind {
1296
1298
UpvarCapture :: ByValue => CaptureKind :: Value ,
1299
+ UpvarCapture :: ByUse => CaptureKind :: Use ,
1297
1300
UpvarCapture :: ByRef ( kind) => match kind {
1298
1301
BorrowKind :: Immutable => CaptureKind :: Ref ( Mutability :: Not ) ,
1299
1302
BorrowKind :: UniqueImmutable | BorrowKind :: Mutable => {
0 commit comments