Skip to content

Commit daa0675

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 daa0675

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

ash/src/vk.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,4 +302,9 @@ mod tests {
302302
fn test_debug_enum() {
303303
assert_eq!(format!("{:?}", vk::ChromaLocation::MIDPOINT), "MIDPOINT");
304304
}
305+
306+
#[test]
307+
fn test_from_raw() {
308+
let _ = <vk::Instance as vk::Handle>::from_raw(20);
309+
}
305310
}

ash/src/vk/macros.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ macro_rules! define_handle {
126126
#[repr(transparent)]
127127
#[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Hash)]
128128
#[$doc_link]
129-
pub struct $name(*mut u8);
129+
pub struct $name(usize);
130130
impl Default for $name {
131131
fn default() -> Self {
132132
Self::null()
@@ -137,20 +137,21 @@ macro_rules! define_handle {
137137
fn as_raw(self) -> u64 {
138138
self.0 as u64
139139
}
140+
140141
fn from_raw(x: u64) -> Self {
141142
Self(x as _)
142143
}
143144
}
144145
unsafe impl Send for $name {}
145146
unsafe impl Sync for $name {}
146147
impl $name {
147-
pub const fn null() -> Self {
148-
Self(::core::ptr::null_mut())
148+
pub fn null() -> Self {
149+
Self(::core::ptr::null_mut::<u8>() as usize)
149150
}
150151
}
151152
impl fmt::Pointer for $name {
152153
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
153-
fmt::Pointer::fmt(&self.0, f)
154+
fmt::LowerHex::fmt(&self.0, f)
154155
}
155156
}
156157
impl fmt::Debug for $name {

0 commit comments

Comments
 (0)