diff options
| author | Eric Holk <ericholk@microsoft.com> | 2022-03-01 16:57:23 -0800 |
|---|---|---|
| committer | Eric Holk <ericholk@microsoft.com> | 2022-03-07 09:43:28 -0800 |
| commit | 170b02702277229ccaae3ffed916bf6dc57548fc (patch) | |
| tree | 4d832d855a50cc45417825afdd6a6953cfed94d4 /compiler | |
| parent | 9f0f46fa4da35bea07c3bedd7bd9e6742d375a27 (diff) | |
| download | rust-170b02702277229ccaae3ffed916bf6dc57548fc.tar.gz rust-170b02702277229ccaae3ffed916bf6dc57548fc.zip | |
Add comments based on code review feedback
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_typeck/src/check/generator_interior.rs | 8 | ||||
| -rw-r--r-- | compiler/rustc_typeck/src/expr_use_visitor.rs | 4 |
2 files changed, 10 insertions, 2 deletions
diff --git a/compiler/rustc_typeck/src/check/generator_interior.rs b/compiler/rustc_typeck/src/check/generator_interior.rs index 30469e2ec7b..74e98f81439 100644 --- a/compiler/rustc_typeck/src/check/generator_interior.rs +++ b/compiler/rustc_typeck/src/check/generator_interior.rs @@ -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 { diff --git a/compiler/rustc_typeck/src/expr_use_visitor.rs b/compiler/rustc_typeck/src/expr_use_visitor.rs index b15f7cf2889..e839822602d 100644 --- a/compiler/rustc_typeck/src/expr_use_visitor.rs +++ b/compiler/rustc_typeck/src/expr_use_visitor.rs @@ -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) } |
