-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #485 from nikomatsakis/issue-484
update tracked struct `created_at` when validated
- Loading branch information
Showing
2 changed files
with
54 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
salsa-2022-tests/tests/tracked-struct-unchanged-in-new-rev.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use test_log::test; | ||
|
||
#[salsa::jar(db = Db)] | ||
struct Jar(MyInput, MyTracked, tracked_fn); | ||
|
||
trait Db: salsa::DbWithJar<Jar> {} | ||
|
||
#[salsa::input(jar = Jar)] | ||
struct MyInput { | ||
field: u32, | ||
} | ||
|
||
#[salsa::tracked(jar = Jar)] | ||
struct MyTracked { | ||
field: u32, | ||
} | ||
|
||
#[salsa::tracked(jar = Jar)] | ||
fn tracked_fn(db: &dyn Db, input: MyInput) -> MyTracked { | ||
MyTracked::new(db, input.field(db) / 2) | ||
} | ||
|
||
#[salsa::db(Jar)] | ||
#[derive(Default)] | ||
struct Database { | ||
storage: salsa::Storage<Self>, | ||
} | ||
|
||
impl salsa::Database for Database {} | ||
|
||
impl Db for Database {} | ||
|
||
#[test] | ||
fn execute() { | ||
let mut db = Database::default(); | ||
|
||
let input1 = MyInput::new(&db, 22); | ||
let input2 = MyInput::new(&db, 44); | ||
let _tracked1 = tracked_fn(&db, input1); | ||
let _tracked2 = tracked_fn(&db, input2); | ||
|
||
// modify the input and change the revision | ||
input1.set_field(&mut db).to(24); | ||
let tracked2 = tracked_fn(&db, input2); | ||
|
||
// this should not panic | ||
tracked2.field(&db); | ||
} |