Skip to content

Commit 170b027

Browse files
committed
Add comments based on code review feedback
1 parent 9f0f46f commit 170b027

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

compiler/rustc_typeck/src/check/generator_interior.rs

+8
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,14 @@ impl<'a, 'tcx> Visitor<'tcx> for InteriorVisitor<'a, 'tcx> {
371371

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

374+
// Typically, the value produced by an expression is consumed by its parent in some way,
375+
// so we only have to check if the parent contains a yield (note that the parent may, for
376+
// example, store the value into a local variable, but then we already consider local
377+
// variables to be live across their scope).
378+
//
379+
// However, in the case of temporary values, we are going to store the value into a
380+
// temporary on the stack that is live for the current temporary scope and then return a
381+
// reference to it. That value may be live across the entire temporary scope.
374382
let scope = if self.drop_ranges.is_borrowed_temporary(expr) {
375383
self.region_scope_tree.temporary_scope(expr.hir_id.local_id)
376384
} else {

compiler/rustc_typeck/src/expr_use_visitor.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ pub trait Delegate<'tcx> {
5151
/// The value found at `place` is being copied.
5252
/// `diag_expr_id` is the id used for diagnostics (see `consume` for more details).
5353
fn copy(&mut self, place_with_id: &PlaceWithHirId<'tcx>, diag_expr_id: hir::HirId) {
54-
// In most cases, treating a copy as a borrow is the right thing, so we forward
55-
// this to the borrow callback by default.
54+
// In most cases, copying data from `x` is equivalent to doing `*&x`, so by default
55+
// we treat a copy of `x` as a borrow of `x`.
5656
self.borrow(place_with_id, diag_expr_id, ty::BorrowKind::ImmBorrow, false)
5757
}
5858

0 commit comments

Comments
 (0)