Closed
Description
The following program (extracted from try_transform_mut
v0.1.0) fails to compile with MIR-based borrow check:
#![feature(nll)]
#![allow(unused_variables)]
pub trait TryTransform {
fn try_transform<F>(self, f: F)
where
Self: Sized,
F: FnOnce(Self);
}
impl<'a, T> TryTransform for &'a mut T {
fn try_transform<F>(self, f: F)
where
Self: Sized,
F: FnOnce(Self),
{
let this: *mut T = self as *mut T;
f(self);
}
}
fn main() {
}
The error is:
error[E0499]: cannot borrow `*self` as mutable more than once at a time
--> src/main.rs:18:11
|
17 | let this: *mut T = self as _;
| ---- first mutable borrow occurs here
18 | f(self);
| ^^^^ second mutable borrow occurs here
|
note: borrowed value must be valid for the lifetime 'a as defined on the impl at 11:6...
--> src/main.rs:11:6
|
11 | impl<'a, T> TryTransform for &'a mut T {
| ^^
I'm not entirely sure what is going on here, but it seems strange. I would not consider the self as _
to be a "borrow" of self
really.