X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=compiler%2Frustc_data_structures%2Fsrc%2Ffunctor.rs;h=84cb417dd89363c64946c1cef65cca0d15d6fd38;hb=fd02567705326884ddb94535d2ab230a9595dc2a;hp=a3d3f988344c6e0663c6f980494da10354b4725e;hpb=ad76883ff99ef28fc650419640bdc91f7d521eae;p=rust.git diff --git a/compiler/rustc_data_structures/src/functor.rs b/compiler/rustc_data_structures/src/functor.rs index a3d3f988344..84cb417dd89 100644 --- a/compiler/rustc_data_structures/src/functor.rs +++ b/compiler/rustc_data_structures/src/functor.rs @@ -34,43 +34,11 @@ impl IdFunctor for Vec { type Inner = T; #[inline] - fn try_map_id(self, mut f: F) -> Result + fn try_map_id(self, f: F) -> Result where F: FnMut(Self::Inner) -> Result, { - struct HoleVec { - vec: Vec>, - hole: Option, - } - - impl Drop for HoleVec { - fn drop(&mut self) { - unsafe { - for (index, slot) in self.vec.iter_mut().enumerate() { - if self.hole != Some(index) { - mem::ManuallyDrop::drop(slot); - } - } - } - } - } - - unsafe { - let (ptr, length, capacity) = self.into_raw_parts(); - let vec = Vec::from_raw_parts(ptr.cast(), length, capacity); - let mut hole_vec = HoleVec { vec, hole: None }; - - for (index, slot) in hole_vec.vec.iter_mut().enumerate() { - hole_vec.hole = Some(index); - let original = mem::ManuallyDrop::take(slot); - let mapped = f(original)?; - *slot = mem::ManuallyDrop::new(mapped); - hole_vec.hole = None; - } - - mem::forget(hole_vec); - Ok(Vec::from_raw_parts(ptr, length, capacity)) - } + self.into_iter().map(f).collect() } }