- let src_derived_from_illegal_borrow = borrowed_place
- .as_local()
- .map_or(false, |local| self.derived_from_illegal_borrow.contains(local));
-
- // Don't emit errors for borrows of values that are *themselves* the result of
- // an illegal borrow (e.g., the outermost `&` in `&&Cell::new(42)`). We want to
- // point the user to the place where the original illegal borrow occurred, not
- // to subsequent borrows of the resulting value.
- let dest_derived_from_illegal_borrow = if !src_derived_from_illegal_borrow {
- self.check_op(ops::MutBorrow(kind)) == CheckOpResult::Forbidden
- } else {
- true
- };
-
- // When the target of the assignment is a local with no projections, it will be
- // marked as derived from an illegal borrow if necessary.
- //
- // FIXME: should we also clear `derived_from_illegal_borrow` when a local is
- // assigned a new value?
-
- if dest_derived_from_illegal_borrow {
- let block = &self.body[location.block];
- let statement = &block.statements[location.statement_index];
- if let StatementKind::Assign(box (dest, _)) = &statement.kind {
- if let Some(dest) = dest.as_local() {
- self.derived_from_illegal_borrow.insert(dest);
- }
- }
- }