From cd7d034039f9adb20f30975751a6f296a6bd3fc6 Mon Sep 17 00:00:00 2001 From: Gray Olson Date: Wed, 10 May 2023 14:19:12 +0200 Subject: [PATCH 1/4] use PhantomData and fix merge --- src/vulkan/mod.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/vulkan/mod.rs b/src/vulkan/mod.rs index 5b01e9a2..177e507b 100644 --- a/src/vulkan/mod.rs +++ b/src/vulkan/mod.rs @@ -9,6 +9,7 @@ use super::allocator; use super::allocator::AllocationType; use ash::vk; use log::{debug, Level}; +use core::marker::PhantomData; use std::fmt; use crate::{ @@ -177,7 +178,7 @@ impl Allocation { /// See the note about safety in [the documentation of Allocation][Allocation#safety] /// /// [`Slab`]: presser::Slab - pub fn try_as_mapped_slab(&mut self) -> Option> { + pub fn try_as_mapped_slab<'a>(&'a mut self) -> Option> { let mapped_ptr = self.mapped_ptr()?.cast().as_ptr(); if self.size > isize::MAX as _ { @@ -188,7 +189,7 @@ impl Allocation { let size = self.size as usize; Some(MappedAllocationSlab { - _borrowed_alloc: self, + _borrowed_alloc: PhantomData, mapped_ptr, size, }) @@ -273,7 +274,7 @@ impl Default for Allocation { /// /// This type should be acquired by calling [`Allocation::try_as_mapped_slab`]. pub struct MappedAllocationSlab<'a> { - _borrowed_alloc: &'a mut Allocation, + _borrowed_alloc: PhantomData<&'a mut Allocation>, mapped_ptr: *mut u8, size: usize, } @@ -298,6 +299,7 @@ unsafe impl presser::Slab for Allocation { fn base_ptr(&self) -> *const u8 { self.mapped_ptr .expect("tried to use a non-mapped Allocation as a Slab") + .0 .as_ptr() .cast() } @@ -305,6 +307,7 @@ unsafe impl presser::Slab for Allocation { fn base_ptr_mut(&mut self) -> *mut u8 { self.mapped_ptr .expect("tried to use a non-mapped Allocation as a Slab") + .0 .as_ptr() .cast() } From db003159f83c5f42e6c6a592cb3dc8f820c341d9 Mon Sep 17 00:00:00 2001 From: Gray Olson Date: Wed, 10 May 2023 14:21:25 +0200 Subject: [PATCH 2/4] fmt --- src/vulkan/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vulkan/mod.rs b/src/vulkan/mod.rs index 177e507b..32a75b20 100644 --- a/src/vulkan/mod.rs +++ b/src/vulkan/mod.rs @@ -8,8 +8,8 @@ pub use visualizer::AllocatorVisualizer; use super::allocator; use super::allocator::AllocationType; use ash::vk; -use log::{debug, Level}; use core::marker::PhantomData; +use log::{debug, Level}; use std::fmt; use crate::{ From 280b51b519703ae409e519b3408d3b2d0dfcc552 Mon Sep 17 00:00:00 2001 From: Gray Olson Date: Wed, 10 May 2023 14:27:14 +0200 Subject: [PATCH 3/4] make clippy happy --- src/vulkan/mod.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/vulkan/mod.rs b/src/vulkan/mod.rs index 32a75b20..3d1861e2 100644 --- a/src/vulkan/mod.rs +++ b/src/vulkan/mod.rs @@ -178,6 +178,9 @@ impl Allocation { /// See the note about safety in [the documentation of Allocation][Allocation#safety] /// /// [`Slab`]: presser::Slab + // best to be explicit where the lifetime is coming from since we're doing unsafe things + // and relying on an inferred liftime type in the PhantomData below + #[allow(clippy::needless_lifetimes)] pub fn try_as_mapped_slab<'a>(&'a mut self) -> Option> { let mapped_ptr = self.mapped_ptr()?.cast().as_ptr(); From 484bbec96dda5c515af2884ae9410213bbd9d607 Mon Sep 17 00:00:00 2001 From: Gray Olson Date: Wed, 10 May 2023 14:58:40 +0200 Subject: [PATCH 4/4] fmt 2 --- src/vulkan/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vulkan/mod.rs b/src/vulkan/mod.rs index 3d1861e2..2d0760a8 100644 --- a/src/vulkan/mod.rs +++ b/src/vulkan/mod.rs @@ -180,7 +180,7 @@ impl Allocation { /// [`Slab`]: presser::Slab // best to be explicit where the lifetime is coming from since we're doing unsafe things // and relying on an inferred liftime type in the PhantomData below - #[allow(clippy::needless_lifetimes)] + #[allow(clippy::needless_lifetimes)] pub fn try_as_mapped_slab<'a>(&'a mut self) -> Option> { let mapped_ptr = self.mapped_ptr()?.cast().as_ptr();