Skip to content

Commit

Permalink
add tests that show improved spans
Browse files Browse the repository at this point in the history
  • Loading branch information
nikomatsakis committed Apr 4, 2024
1 parent 1acbf2b commit e2f6437
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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`
27 changes: 27 additions & 0 deletions salsa-2022-tests/tests/compile-fail/span-input-setter.rs
Original file line number Diff line number Diff line change
@@ -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);
}
18 changes: 18 additions & 0 deletions salsa-2022-tests/tests/compile-fail/span-input-setter.stderr
Original file line number Diff line number Diff line change
@@ -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,
| ^^^^^
30 changes: 30 additions & 0 deletions salsa-2022-tests/tests/compile-fail/span-tracked-getter.rs
Original file line number Diff line number Diff line change
@@ -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);
}
18 changes: 18 additions & 0 deletions salsa-2022-tests/tests/compile-fail/span-tracked-getter.stderr
Original file line number Diff line number Diff line change
@@ -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,
| ^^^^^

0 comments on commit e2f6437

Please sign in to comment.