File tree 1 file changed +4
-0
lines changed
compiler/rustc_typeck/src/check
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(
2003
2003
fn truncate_capture_for_optimization < ' tcx > ( place : & Place < ' tcx > ) -> Place < ' tcx > {
2004
2004
let is_shared_ref = |ty : Ty < ' _ > | matches ! ( ty. kind( ) , ty:: Ref ( .., hir:: Mutability :: Not ) ) ;
2005
2005
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.
2006
2009
let idx = place. projections . iter ( ) . rposition ( |proj| ProjectionKind :: Deref == proj. kind ) ;
2007
2010
2008
2011
match idx {
2012
+ // If that pointer is a shared reference, then we don't need those fields.
2009
2013
Some ( idx) if is_shared_ref ( place. ty_before_projection ( idx) ) => {
2010
2014
Place { projections : place. projections [ 0 ..=idx] . to_vec ( ) , ..place. clone ( ) }
2011
2015
}
You can’t perform that action at this time.
0 commit comments