salsa/tests/tracked_fn_on_input.rs
Niko Matsakis 8a39bf029b wip
2024-07-16 06:04:01 -04:00

35 lines
682 B
Rust

//! Test that a `tracked` fn on a `salsa::input`
//! compiles and executes successfully.
#![allow(warnings)]
#[salsa::jar(db = Db)]
struct Jar(MyInput, tracked_fn);
trait Db: salsa::DbWithJar<Jar> {}
#[salsa::input]
struct MyInput {
field: u32,
}
#[salsa::tracked]
fn tracked_fn(db: &dyn Db, input: MyInput) -> u32 {
input.field(db) * 2
}
#[test]
fn execute() {
#[salsa::db(Jar)]
#[derive(Default)]
struct Database {
storage: salsa::Storage<Self>,
}
impl salsa::Database for Database {}
impl Db for Database {}
let mut db = Database::default();
let input = MyInput::new(&db, 22);
assert_eq!(tracked_fn(&db, input), 44);
}