Add compile-fail test for getter and setter visibility

This commit is contained in:
Mihail Mihov 2022-09-02 03:19:21 +03:00
parent 13facddde2
commit 0a3b74da57
2 changed files with 48 additions and 0 deletions

View file

@ -0,0 +1,31 @@
#[salsa::jar(db = Db)]
pub struct Jar(a::MyInput);
mod a {
use crate::Jar;
#[salsa::input(jar = Jar)]
pub struct MyInput {
field: u32,
}
}
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 {}
fn main() {
let mut db = Database::default();
let input = a::MyInput::new(&mut db, 22);
input.field(&db);
input.set_field(&mut db).to(23);
}

View file

@ -0,0 +1,17 @@
error[E0624]: associated function `field` is private
--> tests/compile-fail/get-set-on-private-field.rs:29:11
|
7 | #[salsa::input(jar = Jar)]
| -------------------------- private associated function defined here
...
29 | input.field(&db);
| ^^^^^ private associated function
error[E0624]: associated function `set_field` is private
--> tests/compile-fail/get-set-on-private-field.rs:30:11
|
7 | #[salsa::input(jar = Jar)]
| -------------------------- private associated function defined here
...
30 | input.set_field(&mut db).to(23);
| ^^^^^^^^^ private associated function