@@ -149,17 +149,6 @@ pub struct Validator<'a, 'mir, 'tcx> {
149
149
150
150
/// The span of the current statement.
151
151
span : Span ,
152
-
153
- /// True if the local was assigned the result of an illegal borrow (`ops::MutBorrow`).
154
- ///
155
- /// This is used to hide errors from {re,}borrowing the newly-assigned local, instead pointing
156
- /// the user to the place where the illegal borrow occurred. This set is only populated once an
157
- /// error has been emitted, so it will never cause an erroneous `mir::Body` to pass validation.
158
- ///
159
- /// FIXME(ecstaticmorse): assert at the end of checking that if `tcx.has_errors() == false`,
160
- /// this set is empty. Note that if we start removing locals from
161
- /// `derived_from_illegal_borrow`, just checking at the end won't be enough.
162
- derived_from_illegal_borrow : BitSet < Local > ,
163
152
}
164
153
165
154
impl Deref for Validator < ' _ , ' mir , ' tcx > {
@@ -213,7 +202,6 @@ impl Validator<'a, 'mir, 'tcx> {
213
202
span : item. body . span ,
214
203
item,
215
204
qualifs,
216
- derived_from_illegal_borrow : BitSet :: new_empty ( item. body . local_decls . len ( ) ) ,
217
205
}
218
206
}
219
207
@@ -406,35 +394,7 @@ impl Visitor<'tcx> for Validator<'_, 'mir, 'tcx> {
406
394
) ;
407
395
408
396
if borrowed_place_has_mut_interior {
409
- let src_derived_from_illegal_borrow = borrowed_place
410
- . as_local ( )
411
- . map_or ( false , |local| self . derived_from_illegal_borrow . contains ( local) ) ;
412
-
413
- // Don't emit errors for borrows of values that are *themselves* the result of
414
- // an illegal borrow (e.g., the outermost `&` in `&&Cell::new(42)`). We want to
415
- // point the user to the place where the original illegal borrow occurred, not
416
- // to subsequent borrows of the resulting value.
417
- let dest_derived_from_illegal_borrow = if !src_derived_from_illegal_borrow {
418
- self . check_op ( ops:: MutBorrow ( kind) ) == CheckOpResult :: Forbidden
419
- } else {
420
- true
421
- } ;
422
-
423
- // When the target of the assignment is a local with no projections, it will be
424
- // marked as derived from an illegal borrow if necessary.
425
- //
426
- // FIXME: should we also clear `derived_from_illegal_borrow` when a local is
427
- // assigned a new value?
428
-
429
- if dest_derived_from_illegal_borrow {
430
- let block = & self . body [ location. block ] ;
431
- let statement = & block. statements [ location. statement_index ] ;
432
- if let StatementKind :: Assign ( box ( dest, _) ) = & statement. kind {
433
- if let Some ( dest) = dest. as_local ( ) {
434
- self . derived_from_illegal_borrow . insert ( dest) ;
435
- }
436
- }
437
- }
397
+ self . check_op ( ops:: MutBorrow ( kind) ) ;
438
398
}
439
399
}
440
400
0 commit comments