mirror of
https://github.com/salsa-rs/salsa.git
synced 2024-10-23 04:46:35 +00:00
Merge pull request #523 from MichaReiser/tracked-fn-interned
Some checks are pending
Book / Book (push) Waiting to run
Book / Deploy (push) Blocked by required conditions
Test / Test (false, beta) (push) Waiting to run
Test / Test (false, stable) (push) Waiting to run
Test / Test (true, nightly) (push) Waiting to run
Test / Miri (push) Waiting to run
Some checks are pending
Book / Book (push) Waiting to run
Book / Deploy (push) Blocked by required conditions
Test / Test (false, beta) (push) Waiting to run
Test / Test (false, stable) (push) Waiting to run
Test / Test (true, nightly) (push) Waiting to run
Test / Miri (push) Waiting to run
Allow interned values as tracked function arguments
This commit is contained in:
commit
431fd14b69
3 changed files with 35 additions and 10 deletions
|
@ -93,6 +93,12 @@ macro_rules! setup_interned_struct {
|
|||
}
|
||||
}
|
||||
|
||||
impl<$db_lt> $zalsa::LookupId<$db_lt> for $Struct<$db_lt> {
|
||||
fn lookup_id(id: salsa::Id, db: &$db_lt dyn $zalsa::Database) -> Self {
|
||||
$Configuration::ingredient(db).interned_value(id)
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Send for $Struct<'_> {}
|
||||
|
||||
unsafe impl Sync for $Struct<'_> {}
|
||||
|
|
|
@ -1,13 +1,3 @@
|
|||
error[E0277]: the trait bound `MyInterned<'_>: LookupId<'_>` is not satisfied
|
||||
--> tests/compile-fail/specify-does-not-work-if-the-key-is-a-salsa-interned.rs:15:1
|
||||
|
|
||||
15 | #[salsa::tracked(specify)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `FromId` is not implemented for `MyInterned<'_>`, which is required by `MyInterned<'_>: LookupId<'_>`
|
||||
|
|
||||
= help: the trait `LookupId<'db>` is implemented for `MyTracked<'db>`
|
||||
= note: required for `MyInterned<'_>` to implement `LookupId<'_>`
|
||||
= note: this error originates in the macro `salsa::plumbing::setup_tracked_fn` which comes from the expansion of the attribute macro `salsa::tracked` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error[E0277]: the trait bound `MyInterned<'_>: TrackedStructInDb` is not satisfied
|
||||
--> tests/compile-fail/specify-does-not-work-if-the-key-is-a-salsa-interned.rs:15:1
|
||||
|
|
||||
|
|
29
tests/tracked_fn_on_interned.rs
Normal file
29
tests/tracked_fn_on_interned.rs
Normal file
|
@ -0,0 +1,29 @@
|
|||
//! Test that a `tracked` fn on a `salsa::interned`
|
||||
//! compiles and executes successfully.
|
||||
|
||||
#[salsa::interned]
|
||||
struct Name<'db> {
|
||||
name: String,
|
||||
}
|
||||
|
||||
#[salsa::tracked]
|
||||
fn tracked_fn<'db>(db: &'db dyn salsa::Database, name: Name<'db>) -> String {
|
||||
name.name(db).clone()
|
||||
}
|
||||
|
||||
#[salsa::db]
|
||||
#[derive(Default)]
|
||||
struct Database {
|
||||
storage: salsa::Storage<Self>,
|
||||
}
|
||||
|
||||
#[salsa::db]
|
||||
impl salsa::Database for Database {}
|
||||
|
||||
#[test]
|
||||
fn execute() {
|
||||
let db = Database::default();
|
||||
let name = Name::new(&db, "Salsa".to_string());
|
||||
|
||||
assert_eq!(tracked_fn(&db, name), "Salsa");
|
||||
}
|
Loading…
Reference in a new issue