1use crate::prelude::*;
2use core::ops::{Deref, DerefMut};
3mod arithmetic;
4
5pub use arithmetic::{AddLogic, DivLogic, MulLogic, NegLogic, RemLogic, SubLogic};
6
7#[diagnostic::on_unimplemented(
9 message = "the type `{Self}` cannot be indexed by `{I}` in logic",
10 label = "`{Self}` cannot be indexed by `{I}` in logic"
11)]
12pub trait IndexLogic<I: ?Sized> {
13 type Item;
14
15 #[logic]
17 #[requires(false)]
18 #[intrinsic("index_logic")]
19 fn index_logic(self, idx: I) -> Self::Item;
20}
21
22pub trait Fin {
23 type Target: ?Sized;
24
25 #[logic(prophetic)]
27 fn fin<'a>(self) -> &'a Self::Target;
28}
29
30impl<T: ?Sized> Fin for &mut T {
31 type Target = T;
32
33 #[logic(prophetic)]
34 #[builtin("fin")]
35 fn fin<'a>(self) -> &'a T {
36 dead
37 }
38}
39
40#[diagnostic::on_unimplemented(message = "no implementation for `{Self} << {Rhs}` in logic")]
42pub trait ShlLogic<Rhs = Self> {
43 type Output;
44
45 #[logic]
46 #[requires(false)]
47 fn shl_logic(self, other: Rhs) -> Self::Output;
48}
49
50#[diagnostic::on_unimplemented(message = "no implementation for `{Self} >> {Rhs}` in logic")]
52pub trait ShrLogic<Rhs = Self> {
53 type Output;
54
55 #[logic]
56 #[requires(false)]
57 fn shr_logic(self, other: Rhs) -> Self::Output;
58}
59
60#[diagnostic::on_unimplemented(message = "no implementation for `{Self} & {Rhs}` in logic")]
62pub trait BitAndLogic<Rhs = Self> {
63 type Output;
64
65 #[logic]
66 #[requires(false)]
67 fn bitand_logic(self, other: Rhs) -> Self::Output;
68}
69
70impl BitAndLogic for bool {
71 type Output = bool;
72
73 #[logic(open, inline)]
74 fn bitand_logic(self, other: bool) -> Self::Output {
75 self && other
76 }
77}
78
79#[diagnostic::on_unimplemented(message = "no implementation for `{Self} | {Rhs}` in logic")]
81pub trait BitOrLogic<Rhs = Self> {
82 type Output;
83
84 #[logic]
85 #[requires(false)]
86 fn bitor_logic(self, other: Rhs) -> Self::Output;
87}
88
89impl BitOrLogic for bool {
90 type Output = bool;
91
92 #[logic(open, inline)]
93 fn bitor_logic(self, other: bool) -> Self::Output {
94 self || other
95 }
96}
97
98#[diagnostic::on_unimplemented(message = "no implementation for `{Self} ^ {Rhs}` in logic")]
100pub trait BitXorLogic<Rhs = Self> {
101 type Output;
102
103 #[logic]
104 #[requires(false)]
105 fn bitxor_logic(self, other: Rhs) -> Self::Output;
106}
107
108impl BitXorLogic for bool {
109 type Output = bool;
110
111 #[logic(open, inline)]
112 fn bitxor_logic(self, other: bool) -> Self::Output {
113 self != other
114 }
115}
116
117#[diagnostic::on_unimplemented(message = "no implementation for `!{Self}` in logic")]
119pub trait NotLogic {
120 type Output;
121
122 #[logic]
123 #[requires(false)]
124 fn not_logic(self) -> Self::Output;
125}
126
127impl NotLogic for bool {
128 type Output = bool;
129
130 #[logic]
131 #[builtin("bool.Bool.notb")]
132 fn not_logic(self) -> Self::Output {
133 dead
134 }
135}
136
137pub trait DerefLogic: Deref {
167 #[logic]
168 fn deref_logic(&self) -> &Self::Target;
169}
170
171pub trait DerefMutLogic: DerefMut + DerefLogic {
173 #[logic]
174 fn deref_mut_logic(&mut self) -> &mut Self::Target;
175}