# temporary-assignment

Disallow assignments into discarded struct and tuple constructions

Assigning through a freshly constructed struct or tuple updates a value discarded at the end of the statement.
Instead, you SHOULD construct the intended value directly or bind it before assigning into it.

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

## Reported

```ds title="main.ds"
struct Point {
    x: int32;
}

function discard(): void {
    Point { x: 1 }.x = 2;
}
```

## Accepted

```ds title="main.ds"
struct Point {
    x: int32;
}

function retain(): Point {
    let point = Point { x: 1 };
    point.x = 2;
    return point;
}
```

## Prior art

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

[language/linter/src/rules/suspicious/temporary_assignment.rs:6](https://github.com/destack-sh/destack/blob/main/language/linter/src/rules/suspicious/temporary_assignment.rs#L6)
