Skip to content

Commit

Permalink
Add comments based on code review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
eholk committed Mar 7, 2022
1 parent 9f0f46f commit 170b027
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions compiler/rustc_typeck/src/check/generator_interior.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,14 @@ impl<'a, 'tcx> Visitor<'tcx> for InteriorVisitor<'a, 'tcx> {

debug!("is_borrowed_temporary: {:?}", self.drop_ranges.is_borrowed_temporary(expr));

// Typically, the value produced by an expression is consumed by its parent in some way,
// so we only have to check if the parent contains a yield (note that the parent may, for
// example, store the value into a local variable, but then we already consider local
// variables to be live across their scope).
//
// However, in the case of temporary values, we are going to store the value into a
// temporary on the stack that is live for the current temporary scope and then return a
// reference to it. That value may be live across the entire temporary scope.
let scope = if self.drop_ranges.is_borrowed_temporary(expr) {
self.region_scope_tree.temporary_scope(expr.hir_id.local_id)
} else {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_typeck/src/expr_use_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ pub trait Delegate<'tcx> {
/// The value found at `place` is being copied.
/// `diag_expr_id` is the id used for diagnostics (see `consume` for more details).
fn copy(&mut self, place_with_id: &PlaceWithHirId<'tcx>, diag_expr_id: hir::HirId) {
// In most cases, treating a copy as a borrow is the right thing, so we forward
// this to the borrow callback by default.
// In most cases, copying data from `x` is equivalent to doing `*&x`, so by default
// we treat a copy of `x` as a borrow of `x`.
self.borrow(place_with_id, diag_expr_id, ty::BorrowKind::ImmBorrow, false)
}

Expand Down

0 comments on commit 170b027

Please sign in to comment.