rust/tests/ui/borrowck/moved-value-suggest-reborrow-issue-127285.fixed
surechen 4821b84b92 If the moved value is a mut reference, it is used in a generic function and it's type is a generic param, it can be reborrowed to avoid moving.
for example:

```rust
struct Y(u32);
// x's type is '& mut Y' and it is used in `fn generic<T>(x: T) {}`.
fn generic<T>(x: T) {}
```

fixes #127285
2024-07-17 10:07:02 +08:00

18 lines
238 B
Rust

//@ run-rustfix
#![allow(dead_code)]
struct X(u32);
impl X {
fn f(&mut self) {
generic(&mut *self);
self.0 += 1;
//~^ ERROR: use of moved value: `self` [E0382]
}
}
fn generic<T>(_x: T) {}
fn main() {}