Skip to content

Commit b0edadb

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 f093870 commit b0edadb

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
@@ -175,3 +175,24 @@ impl<'me, Tuple: Ord> JoinInput<'me, Tuple> for &'me Relation<Tuple> {
175175
&[]
176176
}
177177
}
178+
179+
impl<'me, Tuple: Ord> JoinInput<'me, (Tuple, ())> for &'me Relation<Tuple> {
180+
type RecentTuples = &'me [(Tuple, ())];
181+
type StableTuples = &'me [Relation<(Tuple, ())>];
182+
183+
fn recent(self) -> Self::RecentTuples {
184+
use std::mem;
185+
assert_eq!(mem::size_of::<(Tuple, ())>(), mem::size_of::<Tuple>());
186+
assert_eq!(mem::align_of::<(Tuple, ())>(), mem::align_of::<Tuple>());
187+
188+
// SAFETY: https://rust-lang.github.io/unsafe-code-guidelines/layout/structs-and-tuples.html#structs-with-1-zst-fields
189+
// guarantees that `T` is layout compatible with `(T, ())`, since `()` is a 1-ZST.
190+
let elements: &'me [Tuple] = self.elements.as_slice();
191+
let elements: &'me [(Tuple, ())] = unsafe { std::mem::transmute(elements) };
192+
elements
193+
}
194+
195+
fn stable(self) -> Self::StableTuples {
196+
&[]
197+
}
198+
}

0 commit comments

Comments
 (0)