use crate::prelude::*;
use core::ops::{Deref, DerefMut};
mod arithmetic;
pub use arithmetic::{AddLogic, DivLogic, MulLogic, NegLogic, RemLogic, SubLogic};
#[diagnostic::on_unimplemented(
message = "the type `{Self}` cannot be indexed by `{I}` in logic",
label = "`{Self}` cannot be indexed by `{I}` in logic"
)]
pub trait IndexLogic<I: ?Sized> {
type Item;
#[logic]
#[requires(false)]
#[intrinsic("index_logic")]
fn index_logic(self, idx: I) -> Self::Item;
}
pub trait Fin {
type Target: ?Sized;
#[logic(prophetic)]
fn fin<'a>(self) -> &'a Self::Target;
}
impl<T: ?Sized> Fin for &mut T {
type Target = T;
#[logic(prophetic)]
#[builtin("fin")]
fn fin<'a>(self) -> &'a T {
dead
}
}
#[diagnostic::on_unimplemented(message = "no implementation for `{Self} << {Rhs}` in logic")]
pub trait ShlLogic<Rhs = Self> {
type Output;
#[logic]
#[requires(false)]
fn shl_logic(self, other: Rhs) -> Self::Output;
}
#[diagnostic::on_unimplemented(message = "no implementation for `{Self} >> {Rhs}` in logic")]
pub trait ShrLogic<Rhs = Self> {
type Output;
#[logic]
#[requires(false)]
fn shr_logic(self, other: Rhs) -> Self::Output;
}
#[diagnostic::on_unimplemented(message = "no implementation for `{Self} & {Rhs}` in logic")]
pub trait BitAndLogic<Rhs = Self> {
type Output;
#[logic]
#[requires(false)]
fn bitand_logic(self, other: Rhs) -> Self::Output;
}
impl BitAndLogic for bool {
type Output = bool;
#[logic(open, inline)]
fn bitand_logic(self, other: bool) -> Self::Output {
self && other
}
}
#[diagnostic::on_unimplemented(message = "no implementation for `{Self} | {Rhs}` in logic")]
pub trait BitOrLogic<Rhs = Self> {
type Output;
#[logic]
#[requires(false)]
fn bitor_logic(self, other: Rhs) -> Self::Output;
}
impl BitOrLogic for bool {
type Output = bool;
#[logic(open, inline)]
fn bitor_logic(self, other: bool) -> Self::Output {
self || other
}
}
#[diagnostic::on_unimplemented(message = "no implementation for `{Self} ^ {Rhs}` in logic")]
pub trait BitXorLogic<Rhs = Self> {
type Output;
#[logic]
#[requires(false)]
fn bitxor_logic(self, other: Rhs) -> Self::Output;
}
impl BitXorLogic for bool {
type Output = bool;
#[logic(open, inline)]
fn bitxor_logic(self, other: bool) -> Self::Output {
self != other
}
}
#[diagnostic::on_unimplemented(message = "no implementation for `!{Self}` in logic")]
pub trait NotLogic {
type Output;
#[logic]
#[requires(false)]
fn not_logic(self) -> Self::Output;
}
impl NotLogic for bool {
type Output = bool;
#[logic]
#[builtin("bool.Bool.notb")]
fn not_logic(self) -> Self::Output {
dead
}
}
pub trait DerefLogic: Deref {
#[logic]
fn deref_logic(&self) -> &Self::Target;
}
pub trait DerefMutLogic: DerefMut + DerefLogic {
#[logic]
fn deref_mut_logic(&mut self) -> &mut Self::Target;
}