@@ -1042,6 +1042,7 @@ pub fn can_move_expr_to_closure_no_visit<'tcx>(
1042
1042
#[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
1043
1043
pub enum CaptureKind {
1044
1044
Value ,
1045
+ Use ,
1045
1046
Ref ( Mutability ) ,
1046
1047
}
1047
1048
impl CaptureKind {
@@ -1054,6 +1055,7 @@ impl std::ops::BitOr for CaptureKind {
1054
1055
fn bitor ( self , rhs : Self ) -> Self :: Output {
1055
1056
match ( self , rhs) {
1056
1057
( CaptureKind :: Value , _) | ( _, CaptureKind :: Value ) => CaptureKind :: Value ,
1058
+ ( CaptureKind :: Use , _) | ( _, CaptureKind :: Use ) => CaptureKind :: Use ,
1057
1059
( CaptureKind :: Ref ( Mutability :: Mut ) , CaptureKind :: Ref ( _) )
1058
1060
| ( CaptureKind :: Ref ( _) , CaptureKind :: Ref ( Mutability :: Mut ) ) => CaptureKind :: Ref ( Mutability :: Mut ) ,
1059
1061
( CaptureKind :: Ref ( Mutability :: Not ) , CaptureKind :: Ref ( Mutability :: Not ) ) => CaptureKind :: Ref ( Mutability :: Not ) ,
@@ -1134,7 +1136,7 @@ pub fn capture_local_usage(cx: &LateContext<'_>, e: &Expr<'_>) -> CaptureKind {
1134
1136
} ,
1135
1137
ExprKind :: Let ( let_expr) => {
1136
1138
let mutability = match pat_capture_kind ( cx, let_expr. pat ) {
1137
- CaptureKind :: Value => Mutability :: Not ,
1139
+ CaptureKind :: Value | CaptureKind :: Use => Mutability :: Not ,
1138
1140
CaptureKind :: Ref ( m) => m,
1139
1141
} ;
1140
1142
return CaptureKind :: Ref ( mutability) ;
@@ -1143,7 +1145,7 @@ pub fn capture_local_usage(cx: &LateContext<'_>, e: &Expr<'_>) -> CaptureKind {
1143
1145
let mut mutability = Mutability :: Not ;
1144
1146
for capture in arms. iter ( ) . map ( |arm| pat_capture_kind ( cx, arm. pat ) ) {
1145
1147
match capture {
1146
- CaptureKind :: Value => break ,
1148
+ CaptureKind :: Value | CaptureKind :: Use => break ,
1147
1149
CaptureKind :: Ref ( Mutability :: Mut ) => mutability = Mutability :: Mut ,
1148
1150
CaptureKind :: Ref ( Mutability :: Not ) => ( ) ,
1149
1151
}
@@ -1153,7 +1155,7 @@ pub fn capture_local_usage(cx: &LateContext<'_>, e: &Expr<'_>) -> CaptureKind {
1153
1155
_ => break ,
1154
1156
} ,
1155
1157
Node :: LetStmt ( l) => match pat_capture_kind ( cx, l. pat ) {
1156
- CaptureKind :: Value => break ,
1158
+ CaptureKind :: Value | CaptureKind :: Use => break ,
1157
1159
capture @ CaptureKind :: Ref ( _) => return capture,
1158
1160
} ,
1159
1161
_ => break ,
@@ -1208,6 +1210,8 @@ pub fn can_move_expr_to_closure<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'
1208
1210
if !self . locals . contains ( & local_id) {
1209
1211
let capture = match capture. info . capture_kind {
1210
1212
UpvarCapture :: ByValue => CaptureKind :: Value ,
1213
+ // FIXME add a CaptureKind::Use
1214
+ UpvarCapture :: ByUse => CaptureKind :: Use ,
1211
1215
UpvarCapture :: ByRef ( kind) => match kind {
1212
1216
BorrowKind :: Immutable => CaptureKind :: Ref ( Mutability :: Not ) ,
1213
1217
BorrowKind :: UniqueImmutable | BorrowKind :: Mutable => {
0 commit comments