Skip to content

Commit 5ddcce2

Browse files
leoyvenstomaka
authored andcommitted
Fix future object safety of BufferAccess (#966)
It was recently discovered in rust-lang/rust#50781 that `Self: Trait` bounds in trait methods are really not object-safe. This will be made into a warning by rust-lang/rust#50966, and vulkano will be affected by the warning . Thankfully the fix looks simple, by just moving `fn len` from `BufferAccess` to being directly in `TypedBufferAccess`.
1 parent 0e50cfa commit 5ddcce2

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

vulkano/src/buffer/traits.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,6 @@ pub unsafe trait BufferAccess: DeviceOwned {
3030
/// Returns the size of the buffer in bytes.
3131
fn size(&self) -> usize;
3232

33-
/// Returns the length of the buffer in number of elements.
34-
///
35-
/// This method can only be called for buffers whose type is known to be an array.
36-
#[inline]
37-
fn len(&self) -> usize
38-
where Self: TypedBufferAccess,
39-
Self::Content: Content
40-
{
41-
self.size() / <Self::Content as Content>::indiv_size()
42-
}
43-
4433
/// Builds a `BufferSlice` object holding the buffer by reference.
4534
#[inline]
4635
fn as_buffer_slice(&self) -> BufferSlice<Self::Content, &Self>
@@ -208,6 +197,14 @@ unsafe impl<T> BufferAccess for T
208197
pub unsafe trait TypedBufferAccess: BufferAccess {
209198
/// The type of the content.
210199
type Content: ?Sized;
200+
201+
/// Returns the length of the buffer in number of elements.
202+
///
203+
/// This method can only be called for buffers whose type is known to be an array.
204+
#[inline]
205+
fn len(&self) -> usize where Self::Content: Content {
206+
self.size() / <Self::Content as Content>::indiv_size()
207+
}
211208
}
212209

213210
unsafe impl<T> TypedBufferAccess for T

0 commit comments

Comments
 (0)