Lift the static restriction on the traits

This commit is contained in:
Markus Westerlind 2020-07-21 23:59:28 +02:00
parent 380c4c1dc8
commit ce6428fbbd
9 changed files with 124 additions and 111 deletions

View file

@ -373,7 +373,7 @@ pub(crate) fn query_group(args: TokenStream, input: TokenStream) -> TokenStream
/// single input. You can also use it to invoke this query, though
/// it's more common to use the trait method on the database
/// itself.
#trait_vis fn in_db(self, db: &#dyn_db) -> salsa::QueryTable<'_, Self>
#trait_vis fn in_db(self, db: &#dyn_db) -> salsa::QueryTable<'_, Self, #dyn_db>
{
salsa::plumbing::get_query_table::<#qt>(db)
}
@ -416,6 +416,11 @@ pub(crate) fn query_group(args: TokenStream, input: TokenStream) -> TokenStream
}
}
impl<'d> salsa::QueryDb<'d> for #qt
{
type DynDb = #dyn_db + 'd;
}
// ANCHOR:Query_impl
impl salsa::Query for #qt
{
@ -424,7 +429,6 @@ pub(crate) fn query_group(args: TokenStream, input: TokenStream) -> TokenStream
type Storage = #storage;
type Group = #group_struct;
type GroupStorage = #group_storage;
type DynDb = #dyn_db;
const QUERY_INDEX: u16 = #query_index;
@ -454,7 +458,7 @@ pub(crate) fn query_group(args: TokenStream, input: TokenStream) -> TokenStream
let recover = if let Some(cycle_recovery_fn) = &query.cycle {
quote! {
fn recover(db: &Self::DynDb, cycle: &[salsa::DatabaseKeyIndex], #key_pattern: &<Self as salsa::Query>::Key)
fn recover(db: &<Self as salsa::QueryDb<'_>>::DynDb, cycle: &[salsa::DatabaseKeyIndex], #key_pattern: &<Self as salsa::Query>::Key)
-> Option<<Self as salsa::Query>::Value> {
Some(#cycle_recovery_fn(
db,
@ -471,7 +475,7 @@ pub(crate) fn query_group(args: TokenStream, input: TokenStream) -> TokenStream
// ANCHOR:QueryFunction_impl
impl salsa::plumbing::QueryFunction for #qt
{
fn execute(db: &Self::DynDb, #key_pattern: <Self as salsa::Query>::Key)
fn execute(db: &<Self as salsa::QueryDb<'_>>::DynDb, #key_pattern: <Self as salsa::Query>::Key)
-> <Self as salsa::Query>::Value {
#invoke(db, #(#key_names),*)
}