mirror of
https://github.com/salsa-rs/salsa.git
synced 2025-08-04 11:00:05 +00:00
wip privacy for tracked structs
This commit is contained in:
parent
3304acc5dd
commit
fe90e68c8f
4 changed files with 26 additions and 1 deletions
|
@ -20,6 +20,9 @@ macro_rules! setup_tracked_struct {
|
|||
// Field names
|
||||
field_ids: [$($field_id:ident),*],
|
||||
|
||||
// Visibilities for field accessor methods
|
||||
field_vis: [$($field_vis:vis f),*],
|
||||
|
||||
// Field names
|
||||
field_getter_ids: [$($field_getter_id:ident),*],
|
||||
|
||||
|
@ -197,7 +200,7 @@ macro_rules! setup_tracked_struct {
|
|||
}
|
||||
|
||||
$(
|
||||
pub fn $field_getter_id<$Db>(&self, db: &$db_lt $Db) -> $crate::maybe_cloned_ty!($field_option, $db_lt, $field_ty)
|
||||
$field_vis fn $field_getter_id<$Db>(&self, db: &$db_lt $Db) -> $crate::maybe_cloned_ty!($field_option, $db_lt, $field_ty)
|
||||
where
|
||||
// FIXME(rust-lang/rust#65991): The `db` argument *should* have the type `dyn Database`
|
||||
$Db: ?Sized + $zalsa::Database,
|
||||
|
|
|
@ -77,6 +77,7 @@ impl Macro {
|
|||
let db_lt = db_lifetime::db_lifetime(&self.struct_item.generics);
|
||||
let new_fn = salsa_struct.constructor_name();
|
||||
let field_ids = salsa_struct.field_ids();
|
||||
let field_vis = salsa_struct.field_vis();
|
||||
let field_getter_ids = salsa_struct.field_getter_ids();
|
||||
let field_indices = salsa_struct.field_indices();
|
||||
let id_field_indices = salsa_struct.id_field_indices();
|
||||
|
@ -103,6 +104,7 @@ impl Macro {
|
|||
db_lt: #db_lt,
|
||||
new_fn: #new_fn,
|
||||
field_ids: [#(#field_ids),*],
|
||||
field_vis: [#(#field_vis f),*],
|
||||
field_getter_ids: [#(#field_getter_ids),*],
|
||||
field_tys: [#(#field_tys),*],
|
||||
field_indices: [#(#field_indices),*],
|
||||
|
|
12
tests/compile-fail/get-on-private-tracked-field.rs
Normal file
12
tests/compile-fail/get-on-private-tracked-field.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
mod a {
|
||||
#[salsa::tracked]
|
||||
pub struct MyTracked<'db> {
|
||||
field: u32,
|
||||
}
|
||||
}
|
||||
|
||||
fn test<'db>(db: &'db dyn salsa::Database, tracked: a::MyTracked<'db>) {
|
||||
tracked.field(db);
|
||||
}
|
||||
|
||||
fn main() {}
|
8
tests/compile-fail/get-on-private-tracked-field.stderr
Normal file
8
tests/compile-fail/get-on-private-tracked-field.stderr
Normal file
|
@ -0,0 +1,8 @@
|
|||
error[E0624]: method `field` is private
|
||||
--> tests/compile-fail/get-on-private-tracked-field.rs:9:13
|
||||
|
|
||||
2 | #[salsa::tracked]
|
||||
| ----------------- private method defined here
|
||||
...
|
||||
9 | tracked.field(db);
|
||||
| ^^^^^ private method
|
Loading…
Add table
Add a link
Reference in a new issue