Skip to content

Commit 675b629

Browse files
Allow Relation<T> to be joined with Variable<(T, S)>
This case occurred in `Polonius`, where we had to create a separate `Relation<(T, ())>` to make things work.
1 parent 25c7774 commit 675b629

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/join.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,24 @@ impl<'me, Tuple: Ord> JoinInput<'me, Tuple> for &'me Relation<Tuple> {
179179
&[]
180180
}
181181
}
182+
183+
impl<'me, Tuple: Ord> JoinInput<'me, (Tuple, ())> for &'me Relation<Tuple> {
184+
type RecentTuples = &'me [(Tuple, ())];
185+
type StableTuples = &'me [Relation<(Tuple, ())>];
186+
187+
fn recent(self) -> Self::RecentTuples {
188+
use std::mem;
189+
assert_eq!(mem::size_of::<(Tuple, ())>(), mem::size_of::<Tuple>());
190+
assert_eq!(mem::align_of::<(Tuple, ())>(), mem::align_of::<Tuple>());
191+
192+
// SAFETY: https://rust-lang.github.io/unsafe-code-guidelines/layout/structs-and-tuples.html#structs-with-1-zst-fields
193+
// guarantees that `T` is layout compatible with `(T, ())`, since `()` is a 1-ZST.
194+
let elements: &'me [Tuple] = self.elements.as_slice();
195+
let elements: &'me [(Tuple, ())] = unsafe { std::mem::transmute(elements) };
196+
elements
197+
}
198+
199+
fn stable(self) -> Self::StableTuples {
200+
&[]
201+
}
202+
}

0 commit comments

Comments
 (0)