Closed
Description
On nightly, the following code...
#![feature(nll)]
struct Bar;
impl Bar {
fn bar(&mut self, _: impl Fn()) { }
}
struct Foo { thing: Bar, number: usize }
impl Foo {
fn foo(&mut self) {
self.thing.bar(|| {
&self.number;
});
}
}
...yields this error message:
error[E0502]: cannot borrow `self.thing` as mutable because it is also borrowed as immutable
--> src/lib.rs:13:9
|
13 | self.thing.bar(|| {
| ^ -- immutable borrow occurs here
| _________|
| |_________|
| ||
14 | || &self.number;
| || ---- previous borrow occurs due to use of `self.thing` in closure
15 | || });
| || ^
| ||__________|
| |___________mutable borrow occurs here
| borrow later used here
Since the closure actually borrows self.number
, not self.thing
, I feel like the error should say self
instead of self.thing
. It would also be nice if it weren't an error in the first place, but that's a separate issue (let me know if I should report it separately).
Meta
rustc --version --verbose
:
rustc 1.28.0-nightly (1ffb32147 2018-05-31)
binary: rustc
commit-hash: 1ffb321477d85fb3c95a0be2a0cd89c04dff0d8d
commit-date: 2018-05-31
host: x86_64-unknown-linux-gnu
release: 1.28.0-nightly
LLVM version: 6.0