This commit is contained in:
Niko Matsakis 2024-07-19 08:05:39 -04:00
parent 6377dbadb8
commit 68a3a7fceb
28 changed files with 272 additions and 470 deletions

View file

@ -95,6 +95,13 @@ impl Macro {
}
}
if let (Some(_), Some(token)) = (&self.args.lru, &self.args.specify) {
return Err(syn::Error::new_spanned(
token,
"the `specify` and `lru` options cannot be used together",
));
}
let needs_interner = match function_type {
FunctionType::RequiresInterning => true,
FunctionType::Constant | FunctionType::SalsaStruct => false,

View file

@ -1,15 +1,10 @@
#[salsa::jar(db = Db)]
struct Jar(MyInput, lru_can_not_be_used_with_specify);
trait Db: salsa::DbWithJar<Jar> {}
#[salsa::input]
struct MyInput {
field: u32,
}
#[salsa::tracked(jar = Jar, lru = 3, specify)]
fn lru_can_not_be_used_with_specify(db: &dyn Db, input: MyInput) -> u32 {
#[salsa::tracked(lru = 3, specify)]
fn lru_can_not_be_used_with_specify(db: &dyn salsa::Database, input: MyInput) -> u32 {
input.field(db)
}

View file

@ -1,11 +1,5 @@
error: `specify` and `lru` cannot be used together
--> tests/compile-fail/lru_can_not_be_used_with_specify.rs:11:38
|
11 | #[salsa::tracked(jar = Jar, lru = 3, specify)]
| ^^^^^^^
error[E0412]: cannot find type `lru_can_not_be_used_with_specify` in this scope
--> tests/compile-fail/lru_can_not_be_used_with_specify.rs:2:21
error: the `specify` and `lru` options cannot be used together
--> tests/compile-fail/lru_can_not_be_used_with_specify.rs:6:27
|
2 | struct Jar(MyInput, lru_can_not_be_used_with_specify);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope
6 | #[salsa::tracked(lru = 3, specify)]
| ^^^^^^^

View file

@ -1,9 +1,4 @@
use test_log::test;
#[salsa::jar(db = Db)]
struct Jar(MyInput, MyTracked<'_>, tracked_fn);
trait Db: salsa::DbWithJar<Jar> {}
use salsa::prelude::*;
#[salsa::input]
struct MyInput {
@ -16,31 +11,14 @@ struct MyTracked<'db> {
}
#[salsa::tracked]
fn tracked_fn<'db>(db: &'db dyn Db, input: MyInput) -> MyTracked<'db> {
fn tracked_fn<'db>(db: &'db dyn salsa::Database, input: MyInput) -> MyTracked<'db> {
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]
#[should_panic(expected = "access to tracked struct from previous revision")]
fn execute() {
let mut db = Database::default();
fn main() {
let mut db = salsa::default_database();
let input = MyInput::new(&db, 22);
let tracked = tracked_fn(&db, input);
// modify the input and change the revision
input.set_field(&mut db).to(24);
// panic when reading fields of tracked structs from older revisions
tracked.field(&db);
tracked.field(&db); // tracked comes from prior revision
}

View file

@ -1,5 +1,9 @@
error[E0601]: `main` function not found in crate `$CRATE`
--> tests/compile-fail/panic-when-reading-fields-of-tracked-structs-from-older-revisions.rs:46:2
error[E0502]: cannot borrow `db` as mutable because it is also borrowed as immutable
--> tests/compile-fail/panic-when-reading-fields-of-tracked-structs-from-older-revisions.rs:22:21
|
46 | }
| ^ consider adding a `main` function to `$DIR/tests/compile-fail/panic-when-reading-fields-of-tracked-structs-from-older-revisions.rs`
21 | let tracked = tracked_fn(&db, input);
| --- immutable borrow occurs here
22 | input.set_field(&mut db).to(24);
| ^^^^^^^ mutable borrow occurs here
23 | tracked.field(&db); // tracked comes from prior revision
| ------- immutable borrow later used here

View file

@ -1,6 +1,3 @@
#[salsa::jar(db = Db)]
struct Jar(InputWithBannedName1, InputWithBannedName2);
// Banned field name: `from`
#[salsa::input]
struct InputWithBannedName1 {
@ -13,7 +10,4 @@ struct InputWithBannedName2 {
new: u32,
}
trait Db: salsa::DbWithJar<Jar> {}
fn main() {}
fn main() {}

View file

@ -1,23 +1,11 @@
error: the field name `from` is disallowed in salsa structs
--> tests/compile-fail/salsa_fields_incompatibles.rs:7:5
--> tests/compile-fail/salsa_fields_incompatibles.rs:4:5
|
7 | from: u32,
4 | from: u32,
| ^^^^
error: the field name `new` is disallowed in salsa structs
--> tests/compile-fail/salsa_fields_incompatibles.rs:13:5
--> tests/compile-fail/salsa_fields_incompatibles.rs:10:5
|
13 | new: u32,
10 | new: u32,
| ^^^
error[E0412]: cannot find type `InputWithBannedName1` in this scope
--> tests/compile-fail/salsa_fields_incompatibles.rs:2:12
|
2 | struct Jar(InputWithBannedName1, InputWithBannedName2);
| ^^^^^^^^^^^^^^^^^^^^ not found in this scope
error[E0412]: cannot find type `InputWithBannedName2` in this scope
--> tests/compile-fail/salsa_fields_incompatibles.rs:2:34
|
2 | struct Jar(InputWithBannedName1, InputWithBannedName2);
| ^^^^^^^^^^^^^^^^^^^^ not found in this scope

View file

@ -2,28 +2,18 @@
//!
//! Singleton flags are only allowed for input structs. If applied on any other Salsa struct compilation must fail
mod common;
use common::{HasLogger, Logger};
use test_log::test;
#[salsa::jar(db = Db)]
struct Jar(MyInput, MyTracked, Integers, create_tracked_structs);
trait Db: salsa::DbWithJar<Jar> + HasLogger {}
#[salsa::input(singleton)]
struct MyInput {
field: u32,
}
#[salsa::tracked(singleton)]
struct MyTracked {
struct MyTracked<'db> {
field: u32,
}
#[salsa::tracked(singleton)]
fn create_tracked_structs(db: &dyn Db, input: MyInput) -> Vec<MyTracked> {
fn create_tracked_structs(db: &dyn salsa::Database, input: MyInput) -> Vec<MyTracked> {
(0..input.field(db))
.map(|i| MyTracked::new(db, i))
.collect()
@ -32,21 +22,4 @@ fn create_tracked_structs(db: &dyn Db, input: MyInput) -> Vec<MyTracked> {
#[salsa::accumulator(singleton)]
struct Integers(u32);
#[salsa::db(Jar)]
#[derive(Default)]
struct Database {
storage: salsa::Storage<Self>,
logger: Logger,
}
impl salsa::Database for Database {}
impl Db for Database {}
impl HasLogger for Database {
fn logger(&self) -> &Logger {
&self.logger
}
}
fn main() {}

View file

@ -1,60 +1,11 @@
error[E0583]: file not found for module `common`
--> tests/compile-fail/singleton_only_for_input.rs:5:1
|
5 | mod common;
| ^^^^^^^^^^^
|
= help: to create the module `common`, create file "$DIR/tests/compile-fail/common.rs" or "$DIR/tests/compile-fail/common/mod.rs"
= note: if there is a `mod common` elsewhere in the crate already, import it with `use crate::...` instead
error: `singleton` option not allowed here
--> tests/compile-fail/singleton_only_for_input.rs:20:18
--> tests/compile-fail/singleton_only_for_input.rs:15:18
|
20 | #[salsa::tracked(singleton)]
15 | #[salsa::tracked(singleton)]
| ^^^^^^^^^
error: `singleton` option not allowed here
--> tests/compile-fail/singleton_only_for_input.rs:25:18
--> tests/compile-fail/singleton_only_for_input.rs:22:22
|
25 | #[salsa::tracked(singleton)]
| ^^^^^^^^^
error: `singleton` option not allowed here
--> tests/compile-fail/singleton_only_for_input.rs:32:22
|
32 | #[salsa::accumulator(singleton)]
22 | #[salsa::accumulator(singleton)]
| ^^^^^^^^^
error[E0432]: unresolved imports `common::HasLogger`, `common::Logger`
--> tests/compile-fail/singleton_only_for_input.rs:6:14
|
6 | use common::{HasLogger, Logger};
| ^^^^^^^^^ ^^^^^^ no `Logger` in `common`
| |
| no `HasLogger` in `common`
error[E0412]: cannot find type `MyTracked` in this scope
--> tests/compile-fail/singleton_only_for_input.rs:11:21
|
11 | struct Jar(MyInput, MyTracked, Integers, create_tracked_structs);
| ^^^^^^^^^ not found in this scope
error[E0412]: cannot find type `Integers` in this scope
--> tests/compile-fail/singleton_only_for_input.rs:11:32
|
11 | struct Jar(MyInput, MyTracked, Integers, create_tracked_structs);
| ^^^^^^^^ not found in this scope
error[E0412]: cannot find type `create_tracked_structs` in this scope
--> tests/compile-fail/singleton_only_for_input.rs:11:42
|
11 | struct Jar(MyInput, MyTracked, Integers, create_tracked_structs);
| ^^^^^^^^^^^^^^^^^^^^^^ not found in this scope
warning: unused import: `test_log::test`
--> tests/compile-fail/singleton_only_for_input.rs:8:5
|
8 | use test_log::test;
| ^^^^^^^^^^^^^^
|
= note: `#[warn(unused_imports)]` on by default

View file

@ -1,27 +1,11 @@
#[salsa::jar(db = Db)]
pub struct Jar(MyInput);
pub trait Db: salsa::DbWithJar<Jar> {}
#[salsa::db(Jar)]
#[derive(Default)]
struct Database {
storage: salsa::Storage<Self>,
}
impl salsa::Database for Database {}
impl Db for Database {}
#[salsa::input]
pub struct MyInput {
field: u32,
}
fn main() {
let mut db = Database::default();
let mut db = salsa::default_database();
let input = MyInput::new(&mut db, 22);
input.field(&db);
input.set_field(22);
}

View file

@ -1,18 +1,22 @@
error[E0308]: mismatched types
--> tests/compile-fail/span-input-setter.rs:26:21
--> tests/compile-fail/span-input-setter.rs:10:21
|
26 | input.set_field(22);
| --------- ^^ expected `&mut dyn Db`, found integer
10 | input.set_field(22);
| --------- ^^ expected `&mut _`, found integer
| |
| arguments to this method are incorrect
|
= note: expected mutable reference `&mut (dyn Db + 'static)`
= note: expected mutable reference `&mut _`
found type `{integer}`
note: method defined here
--> tests/compile-fail/span-input-setter.rs:18:5
--> tests/compile-fail/span-input-setter.rs:3:5
|
16 | #[salsa::input]
1 | #[salsa::input]
| ---------------
17 | pub struct MyInput {
18 | field: u32,
2 | pub struct MyInput {
3 | field: u32,
| ^^^^^
help: consider mutably borrowing here
|
10 | input.set_field(&mut 22);
| ++++

View file

@ -1,30 +1,15 @@
#[salsa::jar(db = Db)]
pub struct Jar(MyTracked<'_>, my_fn);
pub trait Db: salsa::DbWithJar<Jar> {}
#[salsa::db(Jar)]
#[derive(Default)]
struct Database {
storage: salsa::Storage<Self>,
}
impl salsa::Database for Database {}
impl Db for Database {}
#[salsa::tracked]
pub struct MyTracked<'db> {
field: u32,
}
#[salsa::tracked]
fn my_fn(db: &dyn crate::Db) {
fn my_fn(db: &dyn salsa::Database) {
let x = MyTracked::new(db, 22);
x.field(22);
}
fn main() {
let db = Database::default();
let mut db = salsa::default_database();
my_fn(&db);
}

View file

@ -1,18 +1,32 @@
error[E0308]: mismatched types
--> tests/compile-fail/span-tracked-getter.rs:24:13
|
24 | x.field(22);
| ----- ^^ expected `&dyn Db`, found integer
| |
| arguments to this method are incorrect
|
= note: expected reference `&(dyn Db + 'static)`
found type `{integer}`
--> tests/compile-fail/span-tracked-getter.rs:9:13
|
9 | x.field(22);
| ----- ^^ expected `&_`, found integer
| |
| arguments to this method are incorrect
|
= note: expected reference `&_`
found type `{integer}`
note: method defined here
--> tests/compile-fail/span-tracked-getter.rs:18:5
--> tests/compile-fail/span-tracked-getter.rs:3:5
|
1 | #[salsa::tracked]
| -----------------
2 | pub struct MyTracked<'db> {
3 | field: u32,
| ^^^^^
help: consider borrowing here
|
9 | x.field(&22);
| +
warning: variable does not need to be mutable
--> tests/compile-fail/span-tracked-getter.rs:13:9
|
16 | #[salsa::tracked]
| -----------------
17 | pub struct MyTracked<'db> {
18 | field: u32,
| ^^^^^
13 | let mut db = salsa::default_database();
| ----^^
| |
| help: remove this `mut`
|
= note: `#[warn(unused_mut)]` on by default

View file

@ -2,11 +2,6 @@
//! compilation fails
#![allow(warnings)]
#[salsa::jar(db = Db)]
struct Jar(MyInput, MyTracked<'_>, tracked_fn);
trait Db: salsa::DbWithJar<Jar> {}
#[salsa::input]
struct MyInput {
field: u32,
@ -17,19 +12,9 @@ struct MyTracked<'db> {
field: u32,
}
#[salsa::tracked(jar = Jar, specify)]
fn tracked_fn<'db>(db: &'db dyn Db, input: MyInput) -> MyTracked<'db> {
#[salsa::tracked(specify)]
fn tracked_fn<'db>(db: &'db dyn salsa::Database, input: MyInput) -> MyTracked<'db> {
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 {}
fn main() {}

View file

@ -1,16 +1,16 @@
error[E0277]: the trait bound `MyInput: TrackedStructInDb<(dyn Db + 'static)>` is not satisfied
--> tests/compile-fail/specify-does-not-work-if-the-key-is-a-salsa-input.rs:20:1
error[E0277]: the trait bound `MyInput: TrackedStructInDb` is not satisfied
--> tests/compile-fail/specify-does-not-work-if-the-key-is-a-salsa-input.rs:15:1
|
20 | #[salsa::tracked(jar = Jar, specify)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TrackedStructInDb<(dyn Db + 'static)>` is not implemented for `MyInput`
15 | #[salsa::tracked(specify)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TrackedStructInDb` is not implemented for `MyInput`
|
= help: the trait `TrackedStructInDb<DB>` is implemented for `MyTracked<'db>`
note: required by a bound in `function::specify::<impl FunctionIngredient<C>>::specify_and_record`
= help: the trait `TrackedStructInDb` is implemented for `MyTracked<'_>`
note: required by a bound in `salsa::function::specify::<impl salsa::plumbing::function::IngredientImpl<C>>::specify_and_record`
--> src/function/specify.rs
|
| pub fn specify_and_record<'db>(&'db self, db: &'db DynDb<C>, key: Id, value: C::Value<'db>)
| pub fn specify_and_record<'db>(&'db self, db: &'db C::DbView, key: Id, value: C::Output<'db>)
| ------------------ required by a bound in this associated function
| where
| C::Input<'db>: TrackedStructInDb<DynDb<C>>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `function::specify::<impl FunctionIngredient<C>>::specify_and_record`
= note: this error originates in the attribute macro `salsa::tracked` (in Nightly builds, run with -Z macro-backtrace for more info)
| C::Input<'db>: TrackedStructInDb,
| ^^^^^^^^^^^^^^^^^ required by this bound in `salsa::function::specify::<impl IngredientImpl<C>>::specify_and_record`
= 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)

View file

@ -2,11 +2,6 @@
//! compilation fails
#![allow(warnings)]
#[salsa::jar(db = Db)]
struct Jar(MyInterned<'_>, MyTracked<'_>, tracked_fn);
trait Db: salsa::DbWithJar<Jar> {}
#[salsa::interned]
struct MyInterned<'db> {
field: u32,
@ -17,19 +12,9 @@ struct MyTracked<'db> {
field: u32,
}
#[salsa::tracked(jar = Jar, specify)]
fn tracked_fn<'db>(db: &'db dyn Db, input: MyInterned<'db>) -> MyTracked<'db> {
#[salsa::tracked(specify)]
fn tracked_fn<'db>(db: &'db dyn salsa::Database, input: MyInterned<'db>) -> MyTracked<'db> {
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 {}
fn main() {}

View file

@ -1,16 +1,26 @@
error[E0277]: the trait bound `MyInterned<'_>: TrackedStructInDb<(dyn Db + 'static)>` is not satisfied
--> tests/compile-fail/specify-does-not-work-if-the-key-is-a-salsa-interned.rs:20:1
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
|
20 | #[salsa::tracked(jar = Jar, specify)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TrackedStructInDb<(dyn Db + 'static)>` is not implemented for `MyInterned<'_>`
15 | #[salsa::tracked(specify)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `FromId` is not implemented for `MyInterned<'_>`, which is required by `MyInterned<'_>: LookupId<'_>`
|
= help: the trait `TrackedStructInDb<DB>` is implemented for `MyTracked<'db>`
note: required by a bound in `function::specify::<impl FunctionIngredient<C>>::specify_and_record`
= 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
|
15 | #[salsa::tracked(specify)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TrackedStructInDb` is not implemented for `MyInterned<'_>`
|
= help: the trait `TrackedStructInDb` is implemented for `MyTracked<'_>`
note: required by a bound in `salsa::function::specify::<impl salsa::plumbing::function::IngredientImpl<C>>::specify_and_record`
--> src/function/specify.rs
|
| pub fn specify_and_record<'db>(&'db self, db: &'db DynDb<C>, key: Id, value: C::Value<'db>)
| pub fn specify_and_record<'db>(&'db self, db: &'db C::DbView, key: Id, value: C::Output<'db>)
| ------------------ required by a bound in this associated function
| where
| C::Input<'db>: TrackedStructInDb<DynDb<C>>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `function::specify::<impl FunctionIngredient<C>>::specify_and_record`
= note: this error originates in the attribute macro `salsa::tracked` (in Nightly builds, run with -Z macro-backtrace for more info)
| C::Input<'db>: TrackedStructInDb,
| ^^^^^^^^^^^^^^^^^ required by this bound in `salsa::function::specify::<impl IngredientImpl<C>>::specify_and_record`
= 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)

View file

@ -1,32 +1,21 @@
#[salsa::jar(db = Db)]
struct Jar(
MyInput,
tracked_fn_with_data,
tracked_fn_with_db,
tracked_fn_with_constructor,
tracked_fn_with_one_input,
tracked_fn_with_receiver_not_applied_to_impl_block,
tracked_fn_with_too_many_arguments_for_specify,
);
trait Db: salsa::DbWithJar<Jar> {}
use salsa::Database as Db;
#[salsa::input]
struct MyInput {
field: u32,
}
#[salsa::tracked(jar = Jar, data = Data)]
#[salsa::tracked(data = Data)]
fn tracked_fn_with_data(db: &dyn Db, input: MyInput) -> u32 {
input.field(db) * 2
}
#[salsa::tracked(jar = Jar, db = Db)]
#[salsa::tracked(db = Db)]
fn tracked_fn_with_db(db: &dyn Db, input: MyInput) -> u32 {
input.field(db) * 2
}
#[salsa::tracked(jar = Jar, constructor = TrackedFn3)]
#[salsa::tracked(constructor = TrackedFn3)]
fn tracked_fn_with_constructor(db: &dyn Db, input: MyInput) -> u32 {
input.field(db) * 2
}
@ -37,7 +26,7 @@ fn tracked_fn_with_one_input(db: &dyn Db) -> u32 {}
#[salsa::tracked]
fn tracked_fn_with_receiver_not_applied_to_impl_block(&self, db: &dyn Db) -> u32 {}
#[salsa::tracked(jar = Jar, specify)]
#[salsa::tracked(specify)]
fn tracked_fn_with_too_many_arguments_for_specify(
db: &dyn Db,
input: MyInput,

View file

@ -1,70 +1,37 @@
error: `data` option not allowed here
--> tests/compile-fail/tracked_fn_incompatibles.rs:19:29
|
19 | #[salsa::tracked(jar = Jar, data = Data)]
| ^^^^
--> tests/compile-fail/tracked_fn_incompatibles.rs:8:18
|
8 | #[salsa::tracked(data = Data)]
| ^^^^
error: `db` option not allowed here
--> tests/compile-fail/tracked_fn_incompatibles.rs:24:29
--> tests/compile-fail/tracked_fn_incompatibles.rs:13:18
|
24 | #[salsa::tracked(jar = Jar, db = Db)]
| ^^
13 | #[salsa::tracked(db = Db)]
| ^^
error: `constructor` option not allowed here
--> tests/compile-fail/tracked_fn_incompatibles.rs:29:29
--> tests/compile-fail/tracked_fn_incompatibles.rs:18:18
|
29 | #[salsa::tracked(jar = Jar, constructor = TrackedFn3)]
| ^^^^^^^^^^^
18 | #[salsa::tracked(constructor = TrackedFn3)]
| ^^^^^^^^^^^
error: #[salsa::tracked] must also be applied to the impl block for tracked methods
--> tests/compile-fail/tracked_fn_incompatibles.rs:38:55
--> tests/compile-fail/tracked_fn_incompatibles.rs:27:55
|
38 | fn tracked_fn_with_receiver_not_applied_to_impl_block(&self, db: &dyn Db) -> u32 {}
| ^
27 | fn tracked_fn_with_receiver_not_applied_to_impl_block(&self, db: &dyn Db) -> u32 {}
| ^^^^^
error: tracked function takes too many arguments to have its value set with `specify`
--> tests/compile-fail/tracked_fn_incompatibles.rs:40:29
error: only functions with a single salsa struct as their input can be specified
--> tests/compile-fail/tracked_fn_incompatibles.rs:29:18
|
40 | #[salsa::tracked(jar = Jar, specify)]
| ^^^^^^^
error[E0412]: cannot find type `tracked_fn_with_data` in this scope
--> tests/compile-fail/tracked_fn_incompatibles.rs:4:5
|
4 | tracked_fn_with_data,
| ^^^^^^^^^^^^^^^^^^^^ not found in this scope
error[E0412]: cannot find type `tracked_fn_with_db` in this scope
--> tests/compile-fail/tracked_fn_incompatibles.rs:5:5
|
5 | tracked_fn_with_db,
| ^^^^^^^^^^^^^^^^^^ not found in this scope
error[E0412]: cannot find type `tracked_fn_with_constructor` in this scope
--> tests/compile-fail/tracked_fn_incompatibles.rs:6:5
|
6 | tracked_fn_with_constructor,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: a struct with a similar name exists: `tracked_fn_with_one_input`
...
34 | #[salsa::tracked]
| ---------------------------- similarly named struct `tracked_fn_with_one_input` defined here
error[E0412]: cannot find type `tracked_fn_with_receiver_not_applied_to_impl_block` in this scope
--> tests/compile-fail/tracked_fn_incompatibles.rs:8:5
|
8 | tracked_fn_with_receiver_not_applied_to_impl_block,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope
error[E0412]: cannot find type `tracked_fn_with_too_many_arguments_for_specify` in this scope
--> tests/compile-fail/tracked_fn_incompatibles.rs:9:5
|
9 | tracked_fn_with_too_many_arguments_for_specify,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope
29 | #[salsa::tracked(specify)]
| ^^^^^^^
error[E0308]: mismatched types
--> tests/compile-fail/tracked_fn_incompatibles.rs:35:46
--> tests/compile-fail/tracked_fn_incompatibles.rs:24:46
|
35 | fn tracked_fn_with_one_input(db: &dyn Db) -> u32 {}
| ------------------------- ^^^ expected `u32`, found `()`
| |
| implicitly returns `()` as its body has no tail or `return` expression
23 | #[salsa::tracked]
| ----------------- implicitly returns `()` as its body has no tail or `return` expression
24 | fn tracked_fn_with_one_input(db: &dyn Db) -> u32 {}
| ^^^ expected `u32`, found `()`

View file

@ -1,6 +1,3 @@
#[salsa::jar(db = Db)]
struct Jar(MyTracked<'_>);
#[salsa::tracked]
struct MyTracked<'db> {
field: u32,
@ -10,6 +7,7 @@ struct MyTracked<'db> {
impl<'db> std::default::Default for MyTracked<'db> {
fn default() -> Self {}
}
#[salsa::tracked(specify)]
impl<'db> std::default::Default for MyTracked<'db> {
fn default() -> Self {}
@ -44,11 +42,10 @@ impl<'db> std::default::Default for MyTracked<'db> {
impl<'db> std::default::Default for MyTracked<'db> {
fn default() -> Self {}
}
#[salsa::tracked]
impl<'db> std::default::Default for [MyTracked<'db>; 12] {
fn default() -> Self {}
}
trait Db: salsa::DbWithJar<Jar> {}
fn main() {}

View file

@ -1,53 +1,69 @@
error: `return_ref` option not allowed here
--> tests/compile-fail/tracked_impl_incompatibles.rs:9:18
error: unexpected token
--> tests/compile-fail/tracked_impl_incompatibles.rs:6:18
|
9 | #[salsa::tracked(return_ref)]
6 | #[salsa::tracked(return_ref)]
| ^^^^^^^^^^
error: `specify` option not allowed here
--> tests/compile-fail/tracked_impl_incompatibles.rs:13:18
error: unexpected token
--> tests/compile-fail/tracked_impl_incompatibles.rs:11:18
|
13 | #[salsa::tracked(specify)]
11 | #[salsa::tracked(specify)]
| ^^^^^^^
error: `no_eq` option not allowed here
--> tests/compile-fail/tracked_impl_incompatibles.rs:18:18
error: unexpected token
--> tests/compile-fail/tracked_impl_incompatibles.rs:16:18
|
18 | #[salsa::tracked(no_eq)]
16 | #[salsa::tracked(no_eq)]
| ^^^^^
error: `data` option not allowed here
--> tests/compile-fail/tracked_impl_incompatibles.rs:23:18
error: unexpected token
--> tests/compile-fail/tracked_impl_incompatibles.rs:21:18
|
23 | #[salsa::tracked(data = Data)]
21 | #[salsa::tracked(data = Data)]
| ^^^^
error: `db` option not allowed here
--> tests/compile-fail/tracked_impl_incompatibles.rs:28:18
error: unexpected token
--> tests/compile-fail/tracked_impl_incompatibles.rs:26:18
|
28 | #[salsa::tracked(db = Db)]
26 | #[salsa::tracked(db = Db)]
| ^^
error: unrecognized option `recover_fn`
--> tests/compile-fail/tracked_impl_incompatibles.rs:33:18
error: unexpected token
--> tests/compile-fail/tracked_impl_incompatibles.rs:31:18
|
33 | #[salsa::tracked(recover_fn = recover)]
31 | #[salsa::tracked(recover_fn = recover)]
| ^^^^^^^^^^
error: `lru` option not allowed here
--> tests/compile-fail/tracked_impl_incompatibles.rs:38:18
error: unexpected token
--> tests/compile-fail/tracked_impl_incompatibles.rs:36:18
|
38 | #[salsa::tracked(lru = 32)]
36 | #[salsa::tracked(lru = 32)]
| ^^^
error: `constructor` option not allowed here
--> tests/compile-fail/tracked_impl_incompatibles.rs:43:18
error: unexpected token
--> tests/compile-fail/tracked_impl_incompatibles.rs:41:18
|
43 | #[salsa::tracked(constructor = Constructor)]
41 | #[salsa::tracked(constructor = Constructor)]
| ^^^^^^^^^^^
error: #[salsa::tracked] can only be applied to salsa structs
--> tests/compile-fail/tracked_impl_incompatibles.rs:48:37
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
--> tests/compile-fail/tracked_impl_incompatibles.rs:47:1
|
48 | impl<'db> std::default::Default for [MyTracked<'db>; 12] {
| ^^^^^^^^^^^^^^^^^^^^
47 | impl<'db> std::default::Default for [MyTracked<'db>; 12] {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^--------------------
| | |
| | this is not defined in the current crate because arrays are always foreign
| impl doesn't use only types from inside the current crate
|
= note: define and implement a trait or new type instead
error[E0308]: mismatched types
--> tests/compile-fail/tracked_impl_incompatibles.rs:48:21
|
48 | fn default() -> Self {}
| ------- ^^^^ expected `[MyTracked<'_>; 12]`, found `()`
| |
| implicitly returns `()` as its body has no tail or `return` expression
|
= note: expected array `[MyTracked<'db>; 12]`
found unit type `()`

View file

@ -1,16 +1,32 @@
#[salsa::jar(db = Db)]
struct Jar(Tracked<'_>);
#[salsa::tracked]
struct Tracked<'db> {
field: u32,
}
#[salsa::tracked]
impl<'db> Tracked<'db> {
#[salsa::tracked]
fn use_tracked(&self) {}
fn ref_self(&self, db: &dyn salsa::Database) {}
}
trait Db: salsa::DbWithJar<Jar> {}
#[salsa::tracked]
impl<'db> Tracked<'db> {
#[salsa::tracked]
fn ref_mut_self(&mut self, db: &dyn salsa::Database) {}
}
#[salsa::tracked]
impl<'db> Tracked<'db> {
#[salsa::tracked]
fn multiple_lifetimes<'db1>(&mut self, db: &'db1 dyn salsa::Database) {}
}
#[salsa::tracked]
impl<'db> Tracked<'db> {
#[salsa::tracked]
fn type_generics<T>(&mut self, db: &dyn salsa::Database) -> T {
panic!()
}
}
fn main() {}

View file

@ -1,5 +1,23 @@
error: #[salsa::tracked] must also be applied to the impl block for tracked methods
--> tests/compile-fail/tracked_method_incompatibles.rs:11:20
error: tracked methods's first argument must be declared as `self`, not `&self` or `&mut self`
--> tests/compile-fail/tracked_method_incompatibles.rs:9:17
|
9 | fn ref_self(&self, db: &dyn salsa::Database) {}
| ^
error: tracked methods's first argument must be declared as `self`, not `&self` or `&mut self`
--> tests/compile-fail/tracked_method_incompatibles.rs:15:21
|
11 | fn use_tracked(&self) {}
| ^
15 | fn ref_mut_self(&mut self, db: &dyn salsa::Database) {}
| ^
error: tracked method already has a lifetime parameter in scope
--> tests/compile-fail/tracked_method_incompatibles.rs:21:27
|
21 | fn multiple_lifetimes<'db1>(&mut self, db: &'db1 dyn salsa::Database) {}
| ^^^^
error: tracked methods cannot have non-lifetime generic parameters
--> tests/compile-fail/tracked_method_incompatibles.rs:27:22
|
27 | fn type_generics<T>(&mut self, db: &dyn salsa::Database) -> T {
| ^

View file

@ -1,8 +1,3 @@
#[salsa::jar(db = Db)]
struct Jar(MyInput, tracked_method_on_untracked_impl);
trait Db: salsa::DbWithJar<Jar> {}
#[salsa::input]
struct MyInput {
field: u32,

View file

@ -1,11 +1,5 @@
error: #[salsa::tracked] must also be applied to the impl block for tracked methods
--> tests/compile-fail/tracked_method_on_untracked_impl.rs:13:41
|
13 | fn tracked_method_on_untracked_impl(self, db: &dyn Db) -> u32 {
| ^^^^
error[E0412]: cannot find type `tracked_method_on_untracked_impl` in this scope
--> tests/compile-fail/tracked_method_on_untracked_impl.rs:2:21
--> tests/compile-fail/tracked_method_on_untracked_impl.rs:8:41
|
2 | struct Jar(MyInput, tracked_method_on_untracked_impl);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope
8 | fn tracked_method_on_untracked_impl(self, db: &dyn Db) -> u32 {
| ^^^^

View file

@ -1,36 +1,31 @@
#[salsa::jar(db = Db)]
struct Jar(TrackedWithRetRef, TrackedSructWithSpecify, TrackedStructWithNoEq, TrackedStructWithDb, TrackedStructWithRecover, TrackedStructWithLru);
trait Db: salsa::DbWithJar<Jar> {}
#[salsa::tracked(jar = Jar, return_ref)]
#[salsa::tracked(return_ref)]
struct TrackedWithRetRef {
field: u32,
field: u32,
}
#[salsa::tracked(jar = Jar, specify)]
#[salsa::tracked(specify)]
struct TrackedSructWithSpecify {
field: u32,
field: u32,
}
#[salsa::tracked(jar = Jar, no_eq)]
#[salsa::tracked(no_eq)]
struct TrackedStructWithNoEq {
field: u32,
field: u32,
}
#[salsa::tracked(jar = Jar, db = Db)]
#[salsa::tracked(db = Db)]
struct TrackedStructWithDb {
field: u32,
field: u32,
}
#[salsa::tracked(jar = Jar, recover_fn = recover)]
#[salsa::tracked(recover_fn = recover)]
struct TrackedStructWithRecover {
field: u32,
field: u32,
}
#[salsa::tracked(jar = Jar, lru =12)]
#[salsa::tracked(lru = 12)]
struct TrackedStructWithLru {
field: u32,
field: u32,
}
fn main() {}
fn main() {}

View file

@ -1,71 +1,35 @@
error: `return_ref` option not allowed here
--> tests/compile-fail/tracked_struct_incompatibles.rs:7:29
--> tests/compile-fail/tracked_struct_incompatibles.rs:1:18
|
7 | #[salsa::tracked(jar = Jar, return_ref)]
| ^^^^^^^^^^
1 | #[salsa::tracked(return_ref)]
| ^^^^^^^^^^
error: `specify` option not allowed here
--> tests/compile-fail/tracked_struct_incompatibles.rs:12:29
|
12 | #[salsa::tracked(jar = Jar, specify)]
| ^^^^^^^
--> tests/compile-fail/tracked_struct_incompatibles.rs:6:18
|
6 | #[salsa::tracked(specify)]
| ^^^^^^^
error: `no_eq` option not allowed here
--> tests/compile-fail/tracked_struct_incompatibles.rs:17:29
--> tests/compile-fail/tracked_struct_incompatibles.rs:11:18
|
17 | #[salsa::tracked(jar = Jar, no_eq)]
| ^^^^^
11 | #[salsa::tracked(no_eq)]
| ^^^^^
error: `db` option not allowed here
--> tests/compile-fail/tracked_struct_incompatibles.rs:22:29
--> tests/compile-fail/tracked_struct_incompatibles.rs:16:18
|
22 | #[salsa::tracked(jar = Jar, db = Db)]
| ^^
16 | #[salsa::tracked(db = Db)]
| ^^
error: unrecognized option `recover_fn`
--> tests/compile-fail/tracked_struct_incompatibles.rs:27:29
--> tests/compile-fail/tracked_struct_incompatibles.rs:21:18
|
27 | #[salsa::tracked(jar = Jar, recover_fn = recover)]
| ^^^^^^^^^^
21 | #[salsa::tracked(recover_fn = recover)]
| ^^^^^^^^^^
error: `lru` option not allowed here
--> tests/compile-fail/tracked_struct_incompatibles.rs:32:29
--> tests/compile-fail/tracked_struct_incompatibles.rs:26:18
|
32 | #[salsa::tracked(jar = Jar, lru =12)]
| ^^^
error[E0412]: cannot find type `TrackedWithRetRef` in this scope
--> tests/compile-fail/tracked_struct_incompatibles.rs:2:12
|
2 | struct Jar(TrackedWithRetRef, TrackedSructWithSpecify, TrackedStructWithNoEq, TrackedStructWithDb, TrackedStructWithRecover, TrackedStruc...
| ^^^^^^^^^^^^^^^^^ not found in this scope
error[E0412]: cannot find type `TrackedSructWithSpecify` in this scope
--> tests/compile-fail/tracked_struct_incompatibles.rs:2:31
|
2 | struct Jar(TrackedWithRetRef, TrackedSructWithSpecify, TrackedStructWithNoEq, TrackedStructWithDb, TrackedStructWithRecover, TrackedStruc...
| ^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope
error[E0412]: cannot find type `TrackedStructWithNoEq` in this scope
--> tests/compile-fail/tracked_struct_incompatibles.rs:2:56
|
2 | struct Jar(TrackedWithRetRef, TrackedSructWithSpecify, TrackedStructWithNoEq, TrackedStructWithDb, TrackedStructWithRecover, TrackedStruc...
| ^^^^^^^^^^^^^^^^^^^^^ not found in this scope
error[E0412]: cannot find type `TrackedStructWithDb` in this scope
--> tests/compile-fail/tracked_struct_incompatibles.rs:2:79
|
2 | struct Jar(TrackedWithRetRef, TrackedSructWithSpecify, TrackedStructWithNoEq, TrackedStructWithDb, TrackedStructWithRecover, TrackedStruc...
| ^^^^^^^^^^^^^^^^^^^ not found in this scope
error[E0412]: cannot find type `TrackedStructWithRecover` in this scope
--> tests/compile-fail/tracked_struct_incompatibles.rs:2:100
|
2 | ...rackedStructWithNoEq, TrackedStructWithDb, TrackedStructWithRecover, TrackedStructWithLru);
| ^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope
error[E0412]: cannot find type `TrackedStructWithLru` in this scope
--> tests/compile-fail/tracked_struct_incompatibles.rs:2:126
|
2 | ...ackedStructWithDb, TrackedStructWithRecover, TrackedStructWithLru);
| ^^^^^^^^^^^^^^^^^^^^ not found in this scope
26 | #[salsa::tracked(lru = 12)]
| ^^^

View file

@ -60,8 +60,8 @@ fn execute() {
assert_eq!(final_result(&db, input), 22);
db.assert_logs(expect![[r#"
[
"final_result(MyInput { [salsa id]: 0 })",
"intermediate_result(MyInput { [salsa id]: 0 })",
"final_result(MyInput { [salsa id]: 0, field: 22 })",
"intermediate_result(MyInput { [salsa id]: 0, field: 22 })",
]"#]]);
// Intermediate result is the same, so final result does
@ -70,14 +70,14 @@ fn execute() {
assert_eq!(final_result(&db, input), 22);
db.assert_logs(expect![[r#"
[
"intermediate_result(MyInput { [salsa id]: 0 })",
"intermediate_result(MyInput { [salsa id]: 0, field: 23 })",
]"#]]);
input.set_field(&mut db).to(24);
assert_eq!(final_result(&db, input), 24);
db.assert_logs(expect![[r#"
[
"intermediate_result(MyInput { [salsa id]: 0 })",
"final_result(MyInput { [salsa id]: 0 })",
"intermediate_result(MyInput { [salsa id]: 0, field: 24 })",
"final_result(MyInput { [salsa id]: 0, field: 24 })",
]"#]]);
}