Skip to content

Commit

Permalink
Fix regression after merge
Browse files Browse the repository at this point in the history
- Simplify the Pointer structure a bit more
  • Loading branch information
celinval committed Jul 25, 2024
1 parent e3d907f commit 5d28e22
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 22 deletions.
16 changes: 9 additions & 7 deletions library/kani/src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,38 @@ use std::ptr;
///
/// We allow the user to provide us with a pointer-like object that we convert as needed.
#[doc(hidden)]
pub trait Pointer<'a> {
pub trait Pointer {
/// Type of the pointed-to data
type Inner: ?Sized;

/// used for havocking on replecement of a `modifies` clause.
unsafe fn assignable(self) -> *mut Self::Inner;
}

impl<'a, 'b, T: ?Sized> Pointer<'a> for &'b T {
impl<T: ?Sized> Pointer for &T {
type Inner = T;
unsafe fn assignable(self) -> *mut Self::Inner {
std::mem::transmute(self as *const T)
self as *const T as *mut T
}
}

impl<'a, 'b, T: ?Sized> Pointer<'a> for &'b mut T {
impl<T: ?Sized> Pointer for &mut T {
type Inner = T;

unsafe fn assignable(self) -> *mut Self::Inner {
self as *mut T
}
}

impl<'a, T: ?Sized> Pointer<'a> for *const T {
impl<T: ?Sized> Pointer for *const T {
type Inner = T;

unsafe fn assignable(self) -> *mut Self::Inner {
std::mem::transmute(self)
self as *mut T
}
}

impl<'a, T: ?Sized> Pointer<'a> for *mut T {
impl<T: ?Sized> Pointer for *mut T {
type Inner = T;
unsafe fn assignable(self) -> *mut Self::Inner {
self
Expand Down
30 changes: 15 additions & 15 deletions library/kani_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,48 +295,48 @@ macro_rules! kani_intrinsics {
}

pub mod internal {
use crate::kani::Arbitrary;
use core::ptr;

/// Helper trait for code generation for `modifies` contracts.
///
/// We allow the user to provide us with a pointer-like object that we convert as needed.
#[doc(hidden)]
pub trait Pointer<'a> {
pub trait Pointer {
/// Type of the pointed-to data
type Inner: ?Sized;

/// used for havocking on replecement of a `modifies` clause.
unsafe fn assignable(self) -> &'a mut Self::Inner;
unsafe fn assignable(self) -> *mut Self::Inner;
}

impl<'a, 'b, T: ?Sized> Pointer<'a> for &'b T {
impl<T: ?Sized> Pointer for &T {
type Inner = T;
#[allow(clippy::transmute_ptr_to_ref)]
unsafe fn assignable(self) -> &'a mut Self::Inner {
$core::mem::transmute(self as *const T)
unsafe fn assignable(self) -> *mut Self::Inner {
self as *const T as *mut T
}
}

impl<'a, 'b, T: ?Sized> Pointer<'a> for &'b mut T {
impl<T: ?Sized> Pointer for &mut T {
type Inner = T;

unsafe fn assignable(self) -> &'a mut Self::Inner {
$core::mem::transmute(self)
unsafe fn assignable(self) -> *mut Self::Inner {
self as *mut T
}
}

impl<'a, T: ?Sized> Pointer<'a> for *const T {
impl<T: ?Sized> Pointer for *const T {
type Inner = T;

unsafe fn assignable(self) -> *mut Self::Inner {
core::mem::transmute(self)
self as *mut T
}
}

impl<'a, T: ?Sized> Pointer<'a> for *mut T {
impl<T: ?Sized> Pointer for *mut T {
type Inner = T;
#[allow(clippy::transmute_ptr_to_ref)]
unsafe fn assignable(self) -> &'a mut Self::Inner {
$core::mem::transmute(self)
unsafe fn assignable(self) -> *mut Self::Inner {
self
}
}

Expand Down

0 comments on commit 5d28e22

Please sign in to comment.