changeset 48567:d1210d56008b

rust: Fix outdated comments in OwningDirstateMap OwningDirstateMap used to own a PyBytes, but was generalized to be more generic when it was moved from hg-cpython to hg-core. This fixes some comments that were still referencing PyBytes. Differential Revision: https://phab.mercurial-scm.org/D12003
author Simon Sapin <simon.sapin@octobus.net>
date Mon, 17 Jan 2022 12:50:13 +0100
parents 50de08904c63
children f13fb742e1d8
files rust/hg-core/src/dirstate_tree/owning.rs
diffstat 1 files changed, 9 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/rust/hg-core/src/dirstate_tree/owning.rs	Fri Jan 14 09:28:44 2022 -0800
+++ b/rust/hg-core/src/dirstate_tree/owning.rs	Mon Jan 17 12:50:13 2022 +0100
@@ -21,7 +21,7 @@
     /// language cannot represent a lifetime referencing a sibling field.
     /// This is not quite a self-referencial struct (moving this struct is not
     /// a problem as it doesn’t change the address of the bytes buffer owned
-    /// by `PyBytes`) but touches similar borrow-checker limitations.
+    /// by `on_disk`) but touches similar borrow-checker limitations.
     ptr: *mut (),
 }
 
@@ -50,13 +50,13 @@
         // SAFETY: We cast the type-erased pointer back to the same type it had
         // in `new`, except with a different lifetime parameter. This time we
         // connect the lifetime to that of `self`. This cast is valid because
-        // `self` owns the same `PyBytes` whose buffer `DirstateMap`
-        // references. That buffer has a stable memory address because the byte
-        // string value of a `PyBytes` is immutable.
+        // `self` owns the same `on_disk` whose buffer `DirstateMap`
+        // references. That buffer has a stable memory address because our
+        // `Self::new_empty` counstructor requires `StableDeref`.
         let ptr: *mut DirstateMap<'a> = self.ptr.cast();
         // SAFETY: we dereference that pointer, connecting the lifetime of the
-        // new   `&mut` to that of `self`. This is valid because the
-        // raw pointer is   to a boxed value, and `self` owns that box.
+        // new `&mut` to that of `self`. This is valid because the
+        // raw pointer is to a boxed value, and `self` owns that box.
         (&self.on_disk, unsafe { &mut *ptr })
     }
 
@@ -65,7 +65,7 @@
     }
 
     pub fn get_map<'a>(&'a self) -> &'a DirstateMap<'a> {
-        // SAFETY: same reasoning as in `get_mut` above.
+        // SAFETY: same reasoning as in `get_pair_mut` above.
         let ptr: *mut DirstateMap<'a> = self.ptr.cast();
         unsafe { &*ptr }
     }
@@ -79,13 +79,13 @@
     fn drop(&mut self) {
         // Silence a "field is never read" warning, and demonstrate that this
         // value is still alive.
-        let _ = &self.on_disk;
+        let _: &Box<dyn Deref<Target = [u8]> + Send> = &self.on_disk;
         // SAFETY: this cast is the same as in `get_mut`, and is valid for the
         // same reason. `self.on_disk` still exists at this point, drop glue
         // will drop it implicitly after this `drop` method returns.
         let ptr: *mut DirstateMap<'_> = self.ptr.cast();
         // SAFETY: `Box::from_raw` takes ownership of the box away from `self`.
-        // This is fine because drop glue does nothig for `*mut ()` and we’re
+        // This is fine because drop glue does nothing for `*mut ()` and we’re
         // in `drop`, so `get` and `get_mut` cannot be called again.
         unsafe { drop(Box::from_raw(ptr)) }
     }