salsa/tests/tracked-struct-id-field-bad-eq.rs

49 lines
942 B
Rust
Raw Normal View History

//! Test an id field whose `PartialEq` impl is always true.
2024-03-16 11:18:52 +00:00
use salsa::{Database, Setter};
2024-03-16 11:18:52 +00:00
use test_log::test;
#[salsa::input]
struct MyInput {
field: bool,
}
#[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]
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() {
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);
}