#![cfg(feature = "inventory")]
use salsa::plumbing::ZalsaDatabase;
#[salsa::interned(no_lifetime, debug)]
struct Name {
text: String,
}
#[salsa::interned(no_lifetime, debug)]
struct Age {
value: u32,
}
#[salsa::input(debug)]
struct Input {
data: u32,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, salsa::Supertype)]
enum DirectOverlap {
First(Name),
Second(Name), }
#[test]
#[should_panic(expected = "overlapping variants")]
fn direct_overlap_detected() {
let db = salsa::DatabaseImpl::new();
let _name = Name::new(&db, "hello".to_string());
let _ =
<DirectOverlap as salsa::plumbing::SalsaStructInDb>::lookup_ingredient_index(db.zalsa());
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, salsa::Supertype)]
enum Inner {
Name(Name),
Age(Age),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, salsa::Supertype)]
enum TransitiveOverlap {
Inner(Inner), Name(Name), }
#[test]
#[should_panic(expected = "overlapping variants")]
fn transitive_overlap_detected() {
let db = salsa::DatabaseImpl::new();
let _name = Name::new(&db, "hello".to_string());
let _ = <TransitiveOverlap as salsa::plumbing::SalsaStructInDb>::lookup_ingredient_index(
db.zalsa(),
);
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, salsa::Supertype)]
enum NoOverlap {
Name(Name),
Age(Age),
}
#[test]
fn no_overlap_is_fine() {
let db = salsa::DatabaseImpl::new();
let _name = Name::new(&db, "hello".to_string());
let _ = <NoOverlap as salsa::plumbing::SalsaStructInDb>::lookup_ingredient_index(db.zalsa());
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, salsa::Supertype)]
enum DisjointInner {
Name(Name),
Age(Age),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, salsa::Supertype)]
enum DisjointOuter {
Inner(DisjointInner),
Input(Input), }
#[test]
fn disjoint_nesting_is_fine() {
let db = salsa::DatabaseImpl::new();
let _name = Name::new(&db, "hello".to_string());
let _ =
<DisjointOuter as salsa::plumbing::SalsaStructInDb>::lookup_ingredient_index(db.zalsa());
}