@@ -798,12 +798,6 @@ enum LocalMutationIsAllowed {
798
798
No ,
799
799
}
800
800
801
- struct AccessErrorsReported {
802
- mutability_error : bool ,
803
- #[ allow( dead_code) ]
804
- conflict_error : bool ,
805
- }
806
-
807
801
#[ derive( Copy , Clone ) ]
808
802
enum InitializationRequiringAction {
809
803
Update ,
@@ -1072,7 +1066,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
1072
1066
kind : ( ShallowOrDeep , ReadOrWrite ) ,
1073
1067
is_local_mutation_allowed : LocalMutationIsAllowed ,
1074
1068
flow_state : & Flows < ' cx , ' gcx , ' tcx > ,
1075
- ) -> AccessErrorsReported {
1069
+ ) {
1076
1070
let ( sd, rw) = kind;
1077
1071
1078
1072
if let Activation ( _, borrow_index) = rw {
@@ -1082,10 +1076,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
1082
1076
place: {:?} borrow_index: {:?}",
1083
1077
place_span. 0 , borrow_index
1084
1078
) ;
1085
- return AccessErrorsReported {
1086
- mutability_error : false ,
1087
- conflict_error : true ,
1088
- } ;
1079
+ return ;
1089
1080
}
1090
1081
}
1091
1082
@@ -1097,10 +1088,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
1097
1088
"access_place: suppressing error place_span=`{:?}` kind=`{:?}`" ,
1098
1089
place_span, kind
1099
1090
) ;
1100
- return AccessErrorsReported {
1101
- mutability_error : false ,
1102
- conflict_error : true ,
1103
- } ;
1091
+ return ;
1104
1092
}
1105
1093
1106
1094
let mutability_error =
@@ -1122,11 +1110,6 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
1122
1110
self . access_place_error_reported
1123
1111
. insert ( ( place_span. 0 . clone ( ) , place_span. 1 ) ) ;
1124
1112
}
1125
-
1126
- AccessErrorsReported {
1127
- mutability_error,
1128
- conflict_error,
1129
- }
1130
1113
}
1131
1114
1132
1115
fn check_access_for_conflict (
@@ -1275,23 +1258,25 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
1275
1258
}
1276
1259
}
1277
1260
1278
- let errors_reported = self . access_place (
1261
+ // Special case: you can assign a immutable local variable
1262
+ // (e.g., `x = ...`) so long as it has never been initialized
1263
+ // before (at this point in the flow).
1264
+ if let & Place :: Local ( local) = place_span. 0 {
1265
+ if let Mutability :: Not = self . mir . local_decls [ local] . mutability {
1266
+ // check for reassignments to immutable local variables
1267
+ self . check_if_reassignment_to_immutable_state ( context, place_span, flow_state) ;
1268
+ return ;
1269
+ }
1270
+ }
1271
+
1272
+ // Otherwise, use the normal access permission rules.
1273
+ self . access_place (
1279
1274
context,
1280
1275
place_span,
1281
1276
( kind, Write ( WriteKind :: Mutate ) ) ,
1282
- // We want immutable upvars to cause an "assignment to immutable var"
1283
- // error, not an "reassignment of immutable var" error, because the
1284
- // latter can't find a good previous assignment span.
1285
- //
1286
- // There's probably a better way to do this.
1287
- LocalMutationIsAllowed :: ExceptUpvars ,
1277
+ LocalMutationIsAllowed :: No ,
1288
1278
flow_state,
1289
1279
) ;
1290
-
1291
- if !errors_reported. mutability_error {
1292
- // check for reassignments to immutable local variables
1293
- self . check_if_reassignment_to_immutable_state ( context, place_span, flow_state) ;
1294
- }
1295
1280
}
1296
1281
1297
1282
fn consume_rvalue (
0 commit comments