@@ -351,12 +351,12 @@ If a closure captures a field of a composite types such as structs, tuples, and
351351* Helper functions:
352352 * ` unsafe_check(Place, Mode) -> (Place, Mode) `
353353 * "Ensure unsafe accesses occur within the closure"
354- * If Place contains a deref of a raw pointer:
355- * Let Place1 = Place truncated just before the deref
356- * Return (Place1, Mode )
357- * If Mode is ` ref * ` and the place contains a field of a packed struct:
358- * Let Place1 = Place truncated just before the field
359- * Return (Place1, Mode )
354+ * If Place contains a deref (at index ` i ` ) of a raw pointer:
355+ * Let ` ( Place1, Mode1) = truncate_place( Place, Mode, i) `
356+ * Return (Place1, Mode1 )
357+ * If Mode is ` ref * ` and the place contains a field of a packed struct at index ` i ` :
358+ * Let ` ( Place1, Mode1) = truncate_place( Place, Mode, i) `
359+ * Return (Place1, Mode1 )
360360 * Else
361361 * Return (Place, Mode)
362362 * ` move_xform(Place, Mode) -> (Place, Mode) ` (For move closures)
@@ -367,16 +367,16 @@ If a closure captures a field of a composite types such as structs, tuples, and
367367 * Return (Place, Mode)
368368 * Else if Mode is ` ref * ` and the place contains a deref of an ` & ` :
369369 * Return (Place, Mode)
370- * Else if place contains a deref:
371- * Let Place1 = Place truncated just before the deref
370+ * Else if place contains a deref at index ` i ` :
371+ * Let ` ( Place1, _) = truncate_place( Place, Mode, i) `
372372 * Return (Place1, ByValue)
373373 * Else:
374374 * Return (Place, ByValue)
375375 * ` ref_xform(Place, Mode) -> (Place, Mode) ` (for ref closures)
376376 * "If taking ownership of data, only move data from enclosing stack frame."
377377 * Generate C' by mapping each (Mode, Place) in C
378- * If Mode is ByValue and place contains a deref:
379- * Let Place1 = Place truncated just before the deref
378+ * If Mode is ByValue and place contains a deref at index ` i ` :
379+ * Let ` ( Place1, _) = truncate_place( Place, Mode, i) `
380380 * Return (Place1, ByValue)
381381 * Else:
382382 * Return (Place, Mode)
@@ -392,6 +392,13 @@ If a closure captures a field of a composite types such as structs, tuples, and
392392 and ` Place.type_before_projection(l) = ty::Ref(.., Mutability::Not) `
393393 * Let Place1 = (Base, Projections[ 0..=l] )
394394 * Return (Place1, Ref)
395+ * ` truncate_place(Place, Mode, len) -> (Place, Mode) `
396+ * "Truncate the place to length ` len ` , i.e. upto but not including index ` len ` "
397+ * "If during truncation we drop Deref of a ` &mut ` and the place was being used by ` ref mut ` , the access to the truncated place must be unique"
398+ * Let (Proj_before, Proj_after) = Place.split_before(len)
399+ * If Mode == ` ref mut ` and there exists ` Deref ` in ` Proj_after ` at index ` i ` such that ` Place.type_before_projection(len + i) ` is ` &mut T `
400+ * Return (Place(Proj_before, ..InputPlace), ` ref-uniq ` )
401+ * Else Return (Place(Proj_before, ..InputPlace), Mode)
395402
396403## Key examples
397404
0 commit comments