rhs_first_assign

CI codecov dependency status Crates.io License

An attribute macro to hack compound assignment.

Motivation

```rust use std::num::Wrapping;

fn main() { let mut xs = vec![Wrapping(1), Wrapping(2)];

// OK
xs[1] = xs[0] + xs[1];

// Error
xs[1] += xs[0];

} ```

error[E0502]: cannot borrow `xs` as immutable because it is also borrowed as mutable --> src/main.rs:10:14 | 10 | xs[1] += xs[0]; | ---------^^--- | | | | | immutable borrow occurs here | mutable borrow occurs here | mutable borrow later used here

Usage

```rust use rhsfirstassign::rhsfirstassign;

use std::num::Wrapping;

[rhsfirstassign]

fn main() { let mut xs = vec![Wrapping(1), Wrapping(2)];

xs[1] = xs[0] + xs[1];

xs[1] += xs[0];

} ```

```rust use std::num::Wrapping;

fn main() { let mut xs = vec![Wrapping(1), Wrapping(2)];

xs[1] = xs[0] + xs[1];

{
    let __rhs_first_assign_rhs_l11_c10 = xs[0];
    xs[1] += __rhs_first_assign_rhs_l11_c10;
};

} ```

License

Licensed under MIT OR Apache-2.0.