add tests that show improved spans

This commit is contained in:
Niko Matsakis 2024-04-04 06:21:33 -04:00
parent 1acbf2b0d4
commit e2f6437890
5 changed files with 95 additions and 2 deletions

View file

@ -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`

View file

@ -0,0 +1,27 @@
#[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 input = MyInput::new(&mut db, 22);
input.field(&db);
input.set_field(22);
}

View file

@ -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,
| ^^^^^

View file

@ -0,0 +1,30 @@
#[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 {
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);
}

View file

@ -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,
| ^^^^^