# prefer-weakest-access

Prefer the weakest access form required by a value's uses

A borrowed parameter with stronger access than any checked use grants callers unnecessary authority.
Instead, you SHOULD declare the weakest access sufficient for every use of the parameter.

- Category: style
- Level: warning
- Fix: suggestion
- Scope: module

## Reported

```ds title="main.ds"
struct Counter {
    value: int32;
}

function read(counter: &exclusive Counter): int32 {
    return counter.value;
}
```

## Accepted

```ds title="main.ds"
struct Counter {
    value: int32;
}

function read(counter: &readonly Counter): int32 {
    return counter.value;
}
```

## Prior art

- [Clippy · needless_pass_by_ref_mut](https://rust-lang.github.io/rust-clippy/master/index.html#needless_pass_by_ref_mut)

[language/linter/src/rules/style/prefer_weakest_access.rs:9](https://github.com/destack-sh/destack/blob/main/language/linter/src/rules/style/prefer_weakest_access.rs#L9)
