wip privacy on interned

This commit is contained in:
Niko Matsakis 2024-07-19 07:14:57 -04:00
parent fe90e68c8f
commit 73a6aed554
4 changed files with 26 additions and 1 deletions

View file

@ -23,6 +23,9 @@ macro_rules! setup_interned_struct {
// Field names
field_ids: [$($field_id:ident),*],
// Visibilities for field accessor methods
field_vis: [$($field_vis:vis f),*],
// Names for field setter methods (typically `set_foo`)
field_getter_ids: [$($field_getter_id:ident),*],
@ -134,7 +137,7 @@ macro_rules! setup_interned_struct {
}
$(
pub fn $field_getter_id<$Db>(self, db: &'db $Db) -> $zalsa::maybe_cloned_ty!($field_option, 'db, $field_ty)
$field_vis fn $field_getter_id<$Db>(self, db: &'db $Db) -> $zalsa::maybe_cloned_ty!($field_option, 'db, $field_ty)
where
// FIXME(rust-lang/rust#65991): The `db` argument *should* have the type `dyn Database`
$Db: ?Sized + $zalsa::Database,

View file

@ -84,6 +84,7 @@ impl Macro {
let field_ids = salsa_struct.field_ids();
let field_indices = salsa_struct.field_indices();
let num_fields = salsa_struct.num_fields();
let field_vis = salsa_struct.field_vis();
let field_getter_ids = salsa_struct.field_getter_ids();
let field_options = salsa_struct.field_options();
let field_tys = salsa_struct.field_tys();
@ -106,6 +107,7 @@ impl Macro {
new_fn: #new_fn,
field_options: [#(#field_options),*],
field_ids: [#(#field_ids),*],
field_vis: [#(#field_vis f),*],
field_getter_ids: [#(#field_getter_ids),*],
field_tys: [#(#field_tys),*],
field_indices: [#(#field_indices),*],

View file

@ -0,0 +1,12 @@
mod a {
#[salsa::interned]
pub struct MyInterned<'db> {
field: u32,
}
}
fn test<'db>(db: &'db dyn salsa::Database, interned: a::MyInterned<'db>) {
interned.field(db);
}
fn main() {}

View file

@ -0,0 +1,8 @@
error[E0624]: method `field` is private
--> tests/compile-fail/get-on-private-interned-field.rs:9:14
|
2 | #[salsa::interned]
| ------------------ private method defined here
...
9 | interned.field(db);
| ^^^^^ private method