2024-04-10 10:34:36 +00:00
|
|
|
//! Test an id field whose `PartialEq` impl is always true.
|
2024-03-16 11:18:52 +00:00
|
|
|
|
2024-07-27 12:29:41 +00:00
|
|
|
use salsa::{Database, Setter};
|
2024-03-16 11:18:52 +00:00
|
|
|
use test_log::test;
|
|
|
|
|
|
|
|
#[salsa::input]
|
|
|
|
struct MyInput {
|
|
|
|
field: bool,
|
|
|
|
}
|
|
|
|
|
2024-04-02 11:04:29 +00:00
|
|
|
#[allow(clippy::derived_hash_with_manual_eq)]
|
2024-03-16 11:18:52 +00:00
|
|
|
#[derive(Eq, Hash, Debug, Clone)]
|
|
|
|
struct BadEq {
|
|
|
|
field: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl PartialEq for BadEq {
|
|
|
|
fn eq(&self, _other: &Self) -> bool {
|
|
|
|
true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<bool> for BadEq {
|
|
|
|
fn from(value: bool) -> Self {
|
|
|
|
Self { field: value }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[salsa::tracked]
|
2024-05-24 01:16:30 +00:00
|
|
|
struct MyTracked<'db> {
|
2024-03-16 11:18:52 +00:00
|
|
|
#[id]
|
|
|
|
field: BadEq,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[salsa::tracked]
|
2024-07-27 12:29:41 +00:00
|
|
|
fn the_fn(db: &dyn Database, input: MyInput) {
|
2024-03-16 11:18:52 +00:00
|
|
|
let tracked0 = MyTracked::new(db, BadEq::from(input.field(db)));
|
|
|
|
assert_eq!(tracked0.field(db).field, input.field(db));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn execute() {
|
2024-07-27 12:29:41 +00:00
|
|
|
let mut db = salsa::DatabaseImpl::new();
|
2024-03-16 11:18:52 +00:00
|
|
|
let input = MyInput::new(&db, true);
|
|
|
|
the_fn(&db, input);
|
|
|
|
input.set_field(&mut db).to(false);
|
|
|
|
the_fn(&db, input);
|
|
|
|
}
|