Skip to content
TE146 · Type · error

Field accessor widens visibility

An accessor may inherit or narrow its field visibility, but it cannot expose a private stored field publicly.

Why this fires

An accessor is part of a stored field's API, so it may inherit or narrow the field visibility but cannot make a private field public.

struct Account {
  balance: int {
    pub get // error[TE146]
  }
}

Allowing this would expose a member whose stored field declaration says it is private.

Fix it

Either remove pub from the accessor or make the field public as well:

pub balance: int {
  pub get
}

Use scoped visibility such as pub(mod) when the accessor should be narrower than a public field.

See also

Search Zolo

9 results

en