# needless-pass-by-value

Disallow passing parameters by value when they are never consumed or mutated

Taking ownership of a move-only parameter prevents callers from retaining it when the body only reads the value.
Instead, you SHOULD accept a readonly borrow when the function neither mutates nor consumes the parameter.
Keep ownership when transferring the value is part of the callable's behavior.

- Category: performance
- Level: warning
- Fix: none
- Scope: module

## Reported

```ds title="main.ds"
struct Packet {
    code: int32;
}

function packetCode(packet: Packet): int32 {
    return packet.code;
}
```

## Accepted

```ds title="main.ds"
struct Packet {
    code: int32;
}

function packetCode(packet: &readonly Packet): int32 {
    return packet.code;
}
```

## Prior art

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

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