Skip to content

Commit 6d68b29

Browse files
committed
Remove integer to pointer cast in Handle implementation
... so that Handle::from_raw is more friendly to miri tests with strict provenance. Closes #996
1 parent 55dc692 commit 6d68b29

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

ash/src/vk.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ pub mod native;
3030
mod platform_types;
3131
pub use platform_types::*;
3232

33+
pub trait DispatchableHandle: Handle {
34+
// We choose to use a pointer type for the parameter to avoid possible integer-to-pointer cast,
35+
// to keep the pointer provenance. See details at https://github.com/ash-rs/ash/issues/996.
36+
fn from_raw(_: *mut u8) -> Self;
37+
}
38+
3339
pub trait Handle: Sized {
3440
const TYPE: ObjectType;
3541
fn as_raw(self) -> u64;

ash/src/vk/macros.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ macro_rules! define_handle {
141141
Self(x as _)
142142
}
143143
}
144+
impl $crate::vk::DispatchableHandle for $name {
145+
fn from_raw(x: *mut u8) -> Self {
146+
Self(x)
147+
}
148+
}
144149
unsafe impl Send for $name {}
145150
unsafe impl Sync for $name {}
146151
impl $name {

0 commit comments

Comments
 (0)