]> git.lizzy.rs Git - rust.git/commitdiff
Explain the math
authorOliver Scherer <github35764891676564198441@oli-obk.de>
Tue, 18 Dec 2018 09:08:37 +0000 (10:08 +0100)
committerOliver Scherer <github35764891676564198441@oli-obk.de>
Tue, 18 Dec 2018 09:08:37 +0000 (10:08 +0100)
src/librustc_mir/interpret/memory.rs

index 65347a02be0c7cf103c8a763fba1e5e99027d69a..77a5f5d7b3a849585232b529b379d1b483301546 100644 (file)
@@ -707,10 +707,15 @@ pub fn copy_repeatedly(
                 new_relocations.extend(
                     relocations
                     .iter()
-                    .map(|&(offset, reloc)| (
-                        offset + dest.offset - src.offset + (i * size),
-                        reloc,
-                    ))
+                    .map(|&(offset, reloc)| {
+                        // compute offset for current repetition
+                        let dest_offset = dest.offset + (i * size);
+                        (
+                            // shift offsets from source allocation to destination allocation
+                            offset + dest_offset - src.offset,
+                            reloc,
+                        )
+                    })
                 );
             }