Clean up BufferContents derive macro expansion further (#2588)

This commit is contained in:
marc0246 2024-10-22 17:12:39 +02:00 committed by GitHub
parent ba278ac193
commit 50b3b7a42f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 12 deletions

View File

@ -165,16 +165,10 @@ pub fn derive_buffer_contents(crate_ident: &Ident, mut ast: DeriveInput) -> Resu
let bounds = bound_types.into_iter().map(|ty| {
quote_spanned! { ty.span() =>
const _: () = {
// HACK: This works around Rust issue #48214, which makes it impossible to put
// these bounds in the where clause of the trait implementation where they actually
// belong until that is resolved.
#[allow(unused)]
fn bound #impl_generics () #where_clause {
fn assert_impl<T: ::#crate_ident::buffer::BufferContents + ?Sized>() {}
assert_impl::<#ty>();
}
};
// HACK: This works around Rust issue #48214, which makes it impossible to put these
// bounds in the where clause of the trait implementation where they actually belong
// until that is resolved.
let _: ::vulkano::buffer::AssertParamIsBufferContents<#ty>;
}
});
@ -187,11 +181,11 @@ pub fn derive_buffer_contents(crate_ident: &Ident, mut ast: DeriveInput) -> Resu
#[inline(always)]
unsafe fn ptr_from_slice(slice: ::std::ptr::NonNull<[u8]>) -> *mut Self {
#( #bounds )*
#ptr_from_slice
}
}
#( #bounds )*
})
}

View File

@ -92,6 +92,7 @@ use std::{
error::Error,
fmt::{Display, Formatter},
hash::{Hash, Hasher},
marker::PhantomData,
ops::Range,
sync::Arc,
};
@ -1066,3 +1067,7 @@ impl From<Subbuffer<[u32]>> for IndexBuffer {
Self::U32(value)
}
}
/// This is intended for use by the `BufferContents` derive macro only.
#[doc(hidden)]
pub struct AssertParamIsBufferContents<T: BufferContents + ?Sized>(PhantomData<T>);