Skip to content

Commit 614f915

Browse files
authored
Use PhantomData in MappedAllocationSlab and fix merge (#167)
* use PhantomData and fix merge * fmt * make clippy happy * fmt 2
1 parent 006ade8 commit 614f915

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/vulkan/mod.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pub use visualizer::AllocatorVisualizer;
88
use super::allocator;
99
use super::allocator::AllocationType;
1010
use ash::vk;
11+
use core::marker::PhantomData;
1112
use log::{debug, Level};
1213
use std::fmt;
1314

@@ -177,7 +178,10 @@ impl Allocation {
177178
/// See the note about safety in [the documentation of Allocation][Allocation#safety]
178179
///
179180
/// [`Slab`]: presser::Slab
180-
pub fn try_as_mapped_slab(&mut self) -> Option<MappedAllocationSlab<'_>> {
181+
// best to be explicit where the lifetime is coming from since we're doing unsafe things
182+
// and relying on an inferred liftime type in the PhantomData below
183+
#[allow(clippy::needless_lifetimes)]
184+
pub fn try_as_mapped_slab<'a>(&'a mut self) -> Option<MappedAllocationSlab<'a>> {
181185
let mapped_ptr = self.mapped_ptr()?.cast().as_ptr();
182186

183187
if self.size > isize::MAX as _ {
@@ -188,7 +192,7 @@ impl Allocation {
188192
let size = self.size as usize;
189193

190194
Some(MappedAllocationSlab {
191-
_borrowed_alloc: self,
195+
_borrowed_alloc: PhantomData,
192196
mapped_ptr,
193197
size,
194198
})
@@ -273,7 +277,7 @@ impl Default for Allocation {
273277
///
274278
/// This type should be acquired by calling [`Allocation::try_as_mapped_slab`].
275279
pub struct MappedAllocationSlab<'a> {
276-
_borrowed_alloc: &'a mut Allocation,
280+
_borrowed_alloc: PhantomData<&'a mut Allocation>,
277281
mapped_ptr: *mut u8,
278282
size: usize,
279283
}
@@ -298,13 +302,15 @@ unsafe impl presser::Slab for Allocation {
298302
fn base_ptr(&self) -> *const u8 {
299303
self.mapped_ptr
300304
.expect("tried to use a non-mapped Allocation as a Slab")
305+
.0
301306
.as_ptr()
302307
.cast()
303308
}
304309

305310
fn base_ptr_mut(&mut self) -> *mut u8 {
306311
self.mapped_ptr
307312
.expect("tried to use a non-mapped Allocation as a Slab")
313+
.0
308314
.as_ptr()
309315
.cast()
310316
}

0 commit comments

Comments
 (0)