File tree Expand file tree Collapse file tree 1 file changed +4
-0
lines changed
compiler/rustc_typeck/src/check Expand file tree Collapse file tree 1 file changed +4
-0
lines changed Original file line number Diff line number Diff line change @@ -2003,9 +2003,13 @@ fn determine_place_ancestry_relation(
20032003fn 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 }
You can’t perform that action at this time.
0 commit comments