about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2021-07-06 20:52:53 -0400
committerGitHub <noreply@github.com>2021-07-06 20:52:53 -0400
commit38dcae2cda85916d91d727ffe08a944e69ee3162 (patch)
tree4a8f222f10559036754547e622c497cc2864abd4
parent32fa96486a5a9969d6151cf436dca4a31f8da292 (diff)
downloadrust-38dcae2cda85916d91d727ffe08a944e69ee3162.tar.gz
rust-38dcae2cda85916d91d727ffe08a944e69ee3162.zip
Apply suggestions from code review
-rw-r--r--compiler/rustc_typeck/src/check/upvar.rs4
1 files changed, 4 insertions, 0 deletions
diff --git a/compiler/rustc_typeck/src/check/upvar.rs b/compiler/rustc_typeck/src/check/upvar.rs
index 8418626b8e6..86d978718dd 100644
--- a/compiler/rustc_typeck/src/check/upvar.rs
+++ b/compiler/rustc_typeck/src/check/upvar.rs
@@ -2003,9 +2003,13 @@ fn determine_place_ancestry_relation(
 fn truncate_capture_for_optimization<'tcx>(place: &Place<'tcx>) -> Place<'tcx> {
     let is_shared_ref = |ty: Ty<'_>| matches!(ty.kind(), ty::Ref(.., hir::Mutability::Not));
 
+    // Find the right-most deref (if any). All the projections that come after this
+    // are fields or other "in-place pointer adjustments"; these refer therefore to
+    // data owned by whatever pointer is being dereferenced here.
     let idx = place.projections.iter().rposition(|proj| ProjectionKind::Deref == proj.kind);
 
     match idx {
+        // If that pointer is a shared reference, then we don't need those fields.
         Some(idx) if is_shared_ref(place.ty_before_projection(idx)) => {
             Place { projections: place.projections[0..=idx].to_vec(), ..place.clone() }
         }