> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sifr.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# SIFR-OWN-0002: Conflicting borrow.

> Conflicting borrow.

`SIFR-OWN-0002` belongs to the **Ownership and borrowing** diagnostic family. It means: conflicting borrow.

## Why It Happens

The ownership model would be violated. Move values only once, keep borrows scoped, and cross task/channel/IPC boundaries only with owned values that satisfy the required safety traits.

<Info>
  Use `sifr --explain SIFR-OWN-0002` locally to see the renderer's exact message template and any machine-applicable suggestions for the compiler version you are running.
</Info>

## Erroneous Code

The same storage cannot participate in conflicting reads, moves, or mutable
borrows. Most often this happens when an overlapping field read, shared borrow,
mutable borrow, or owned move occurs in the same call as a mutable receiver or
mutable argument. It can also happen when a second `anext()` advance starts
before the first pending advance has been awaited.

```python theme={null}
class Buffer:
    values: list[int]

    def replace_from(self, own other: Buffer) -> None:
        self.values = other.values

def replace_with_self(mut buffer: Buffer) -> None:
    buffer.replace_from(buffer)
```

## How To Fix It

Use a disjoint place for every other argument while a mutable receiver or
argument is active. If an argument only needs a value derived from the same
place, snapshot that value in a local before the call. For example, rewrite
`values.append(len(values))` as:

```python theme={null}
count = len(values)
values.append(count)
```

For async generators, await the pending `anext()` result before starting the
next advance.

For example, this starts a second advance while the first one still holds the
generator:

```python theme={null}
agen = numbers()
first = anext(agen)
second = anext(agen)
```

Await each advance before starting the next one:

```python theme={null}
agen = numbers()
first = await anext(agen)
second = await anext(agen)
```

## Fixed Code

```python theme={null}
class Buffer:
    values: list[int]

    def replace_from(self, own other: Buffer) -> None:
        self.values = other.values

def replace(mut target: Buffer, own source: Buffer) -> None:
    target.replace_from(source)
```

## Details

| Field                  | Value                                               |
| ---------------------- | --------------------------------------------------- |
| Code                   | `SIFR-OWN-0002`                                     |
| Family                 | `OWN`                                               |
| Severity               | Error                                               |
| Stability              | stable                                              |
| Owner                  | `sifr_lowering::lower`                              |
| Representative fixture | `crates/sifr/tests/e2e/fail/double_mut_borrow.sifr` |

See the [Error Codes index](/diagnostics/error-codes) for the complete catalog.
