From da3c03206c4fc0fb1af58a609b9e354bb5b26911 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Fri, 30 Jun 2023 23:33:24 +0900 Subject: [PATCH] tree: remove useless pinning of Tree object Since Tree is Unpin, Pin> can be moved and it's basically the same as Box. I heard using Box still violates strict aliasing rule, but Pin wouldn't give any additional guarantee. https://morestina.net/blog/1868/self-referential-types-for-fun-and-profit --- lib/src/tree.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/src/tree.rs b/lib/src/tree.rs index 8930d7dfc..7f5a75123 100644 --- a/lib/src/tree.rs +++ b/lib/src/tree.rs @@ -17,7 +17,6 @@ use std::fmt::{Debug, Error, Formatter}; use std::hash::{Hash, Hasher}; use std::io::Read; use std::iter::Peekable; -use std::pin::Pin; use std::sync::Arc; use itertools::Itertools; @@ -241,12 +240,12 @@ pub struct TreeEntriesIterator<'matcher> { struct TreeEntriesDirItem { entry_iterator: TreeEntriesNonRecursiveIterator<'static>, // On drop, tree must outlive entry_iterator - tree: Pin>, + tree: Box, } impl TreeEntriesDirItem { fn new(tree: Tree) -> Self { - let tree = Box::pin(tree); + let tree = Box::new(tree); let entry_iterator = tree.entries_non_recursive(); let entry_iterator: TreeEntriesNonRecursiveIterator<'static> = unsafe { std::mem::transmute(entry_iterator) }; @@ -410,8 +409,8 @@ struct TreeDiffDirItem { // Iterator over the diffs between tree1 and tree2 entry_iterator: TreeEntryDiffIterator<'static>, // On drop, tree1 and tree2 must outlive entry_iterator - tree1: Pin>, - tree2: Pin>, + tree1: Box, + tree2: Box, } enum TreeDiffItem { @@ -434,8 +433,8 @@ impl<'matcher> TreeDiffIterator<'matcher> { impl TreeDiffDirItem { fn new(path: RepoPath, tree1: Tree, tree2: Tree) -> Self { - let tree1 = Box::pin(tree1); - let tree2 = Box::pin(tree2); + let tree1 = Box::new(tree1); + let tree2 = Box::new(tree2); let iter: TreeEntryDiffIterator = diff_entries(&tree1, &tree2); let iter: TreeEntryDiffIterator<'static> = unsafe { std::mem::transmute(iter) }; Self {