@@ -149,17 +149,6 @@ pub struct Validator<'a, 'mir, 'tcx> {
149149
150150 /// The span of the current statement.
151151 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 > ,
163152}
164153
165154impl Deref for Validator < ' _ , ' mir , ' tcx > {
@@ -213,7 +202,6 @@ impl Validator<'a, 'mir, 'tcx> {
213202 span : item. body . span ,
214203 item,
215204 qualifs,
216- derived_from_illegal_borrow : BitSet :: new_empty ( item. body . local_decls . len ( ) ) ,
217205 }
218206 }
219207
@@ -406,35 +394,7 @@ impl Visitor<'tcx> for Validator<'_, 'mir, 'tcx> {
406394 ) ;
407395
408396 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) ) ;
438398 }
439399 }
440400
0 commit comments