Skip to content

Commit 38dcae2

Browse files
authored
Apply suggestions from code review
1 parent 32fa964 commit 38dcae2

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

compiler/rustc_typeck/src/check/upvar.rs

+4
Original file line numberDiff line numberDiff line change
@@ -2003,9 +2003,13 @@ fn determine_place_ancestry_relation(
20032003
fn truncate_capture_for_optimization<'tcx>(place: &Place<'tcx>) -> Place<'tcx> {
20042004
let is_shared_ref = |ty: Ty<'_>| matches!(ty.kind(), ty::Ref(.., hir::Mutability::Not));
20052005

2006+
// Find the right-most deref (if any). All the projections that come after this
2007+
// are fields or other "in-place pointer adjustments"; these refer therefore to
2008+
// data owned by whatever pointer is being dereferenced here.
20062009
let idx = place.projections.iter().rposition(|proj| ProjectionKind::Deref == proj.kind);
20072010

20082011
match idx {
2012+
// If that pointer is a shared reference, then we don't need those fields.
20092013
Some(idx) if is_shared_ref(place.ty_before_projection(idx)) => {
20102014
Place { projections: place.projections[0..=idx].to_vec(), ..place.clone() }
20112015
}

0 commit comments

Comments
 (0)