From e2f6437890fd038bce10f870e380b71953ef7515 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Thu, 4 Apr 2024 06:21:33 -0400 Subject: [PATCH] add tests that show improved spans --- .../input_struct_id_fields_no_setters.stderr | 4 +-- .../tests/compile-fail/span-input-setter.rs | 27 +++++++++++++++++ .../compile-fail/span-input-setter.stderr | 18 +++++++++++ .../tests/compile-fail/span-tracked-getter.rs | 30 +++++++++++++++++++ .../compile-fail/span-tracked-getter.stderr | 18 +++++++++++ 5 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 salsa-2022-tests/tests/compile-fail/span-input-setter.rs create mode 100644 salsa-2022-tests/tests/compile-fail/span-input-setter.stderr create mode 100644 salsa-2022-tests/tests/compile-fail/span-tracked-getter.rs create mode 100644 salsa-2022-tests/tests/compile-fail/span-tracked-getter.stderr diff --git a/salsa-2022-tests/tests/compile-fail/input_struct_id_fields_no_setters.stderr b/salsa-2022-tests/tests/compile-fail/input_struct_id_fields_no_setters.stderr index 7a2d6c5..aa6227d 100644 --- a/salsa-2022-tests/tests/compile-fail/input_struct_id_fields_no_setters.stderr +++ b/salsa-2022-tests/tests/compile-fail/input_struct_id_fields_no_setters.stderr @@ -1,8 +1,8 @@ error[E0599]: no method named `set_id_one` found for struct `MyInput` in the current scope --> tests/compile-fail/input_struct_id_fields_no_setters.rs:30:11 | -7 | #[salsa::input(jar = Jar)] - | -------------------------- method `set_id_one` not found for this struct +8 | struct MyInput { + | ------- method `set_id_one` not found for this struct ... 30 | input.set_id_one(1); | ^^^^^^^^^^ help: there is a method with a similar name: `id_one` diff --git a/salsa-2022-tests/tests/compile-fail/span-input-setter.rs b/salsa-2022-tests/tests/compile-fail/span-input-setter.rs new file mode 100644 index 0000000..422c81c --- /dev/null +++ b/salsa-2022-tests/tests/compile-fail/span-input-setter.rs @@ -0,0 +1,27 @@ +#[salsa::jar(db = Db)] +pub struct Jar(MyInput); + +pub trait Db: salsa::DbWithJar {} + +#[salsa::db(Jar)] +#[derive(Default)] +struct Database { + storage: salsa::Storage, +} + +impl salsa::Database for Database {} + +impl Db for Database {} + +#[salsa::input] +pub struct MyInput { + field: u32, +} + +fn main() { + let mut db = Database::default(); + let input = MyInput::new(&mut db, 22); + + input.field(&db); + input.set_field(22); +} diff --git a/salsa-2022-tests/tests/compile-fail/span-input-setter.stderr b/salsa-2022-tests/tests/compile-fail/span-input-setter.stderr new file mode 100644 index 0000000..187cc84 --- /dev/null +++ b/salsa-2022-tests/tests/compile-fail/span-input-setter.stderr @@ -0,0 +1,18 @@ +error[E0308]: mismatched types + --> tests/compile-fail/span-input-setter.rs:26:21 + | +26 | input.set_field(22); + | --------- ^^ expected `&mut dyn Db`, found integer + | | + | arguments to this method are incorrect + | + = note: expected mutable reference `&mut dyn Db` + found type `{integer}` +note: method defined here + --> tests/compile-fail/span-input-setter.rs:18:5 + | +16 | #[salsa::input] + | --------------- +17 | pub struct MyInput { +18 | field: u32, + | ^^^^^ diff --git a/salsa-2022-tests/tests/compile-fail/span-tracked-getter.rs b/salsa-2022-tests/tests/compile-fail/span-tracked-getter.rs new file mode 100644 index 0000000..2dbcb9c --- /dev/null +++ b/salsa-2022-tests/tests/compile-fail/span-tracked-getter.rs @@ -0,0 +1,30 @@ +#[salsa::jar(db = Db)] +pub struct Jar(MyTracked, my_fn); + +pub trait Db: salsa::DbWithJar {} + +#[salsa::db(Jar)] +#[derive(Default)] +struct Database { + storage: salsa::Storage, +} + +impl salsa::Database for Database {} + +impl Db for Database {} + +#[salsa::tracked] +pub struct MyTracked { + field: u32, +} + +#[salsa::tracked] +fn my_fn(db: &dyn crate::Db) { + let x = MyTracked::new(db, 22); + x.field(22); +} + +fn main() { + let mut db = Database::default(); + my_fn(&db); +} diff --git a/salsa-2022-tests/tests/compile-fail/span-tracked-getter.stderr b/salsa-2022-tests/tests/compile-fail/span-tracked-getter.stderr new file mode 100644 index 0000000..44e5408 --- /dev/null +++ b/salsa-2022-tests/tests/compile-fail/span-tracked-getter.stderr @@ -0,0 +1,18 @@ +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` + found type `{integer}` +note: method defined here + --> tests/compile-fail/span-tracked-getter.rs:18:5 + | +16 | #[salsa::tracked] + | ----------------- +17 | pub struct MyTracked { +18 | field: u32, + | ^^^^^