diff options
| author | Santiago Pastorino <spastorino@gmail.com> | 2018-06-20 01:31:33 -0300 |
|---|---|---|
| committer | Santiago Pastorino <spastorino@gmail.com> | 2018-06-20 09:04:52 -0300 |
| commit | 3d31e5ffa62cbfce126a2f025bc0e308e464e577 (patch) | |
| tree | 8b9d47d22dba1f7decaa1f48cf1349128940a17f /src | |
| parent | ac8d1f7623f55746ff8f59d6b26f03c39cee5844 (diff) | |
| download | rust-3d31e5ffa62cbfce126a2f025bc0e308e464e577.tar.gz rust-3d31e5ffa62cbfce126a2f025bc0e308e464e577.zip | |
Fix variable name in E0502 double borrow error
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc_mir/borrow_check/error_reporting.rs | 3 | ||||
| -rw-r--r-- | src/test/ui/nll/issue-51268.rs | 35 | ||||
| -rw-r--r-- | src/test/ui/nll/issue-51268.stderr | 20 |
3 files changed, 58 insertions, 0 deletions
diff --git a/src/librustc_mir/borrow_check/error_reporting.rs b/src/librustc_mir/borrow_check/error_reporting.rs index 38d1ac2cb4a..891d5de2f45 100644 --- a/src/librustc_mir/borrow_check/error_reporting.rs +++ b/src/librustc_mir/borrow_check/error_reporting.rs @@ -364,6 +364,9 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { }; if let Some((_, var_span)) = old_closure_span { + let place = &issued_borrow.borrowed_place; + let desc_place = self.describe_place(place).unwrap_or("_".to_owned()); + err.span_label( var_span, format!( diff --git a/src/test/ui/nll/issue-51268.rs b/src/test/ui/nll/issue-51268.rs new file mode 100644 index 00000000000..6edd4a343c2 --- /dev/null +++ b/src/test/ui/nll/issue-51268.rs @@ -0,0 +1,35 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// ignore-tidy-linelength + +#![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(|| { + //~^ ERROR cannot borrow `self.thing` as mutable because it is also borrowed as immutable [E0502] + &self.number; + }); + } +} + +fn main() {} diff --git a/src/test/ui/nll/issue-51268.stderr b/src/test/ui/nll/issue-51268.stderr new file mode 100644 index 00000000000..269bc368305 --- /dev/null +++ b/src/test/ui/nll/issue-51268.stderr @@ -0,0 +1,20 @@ +error[E0502]: cannot borrow `self.thing` as mutable because it is also borrowed as immutable + --> $DIR/issue-51268.rs:28:9 + | +LL | self.thing.bar(|| { + | ^ -- immutable borrow occurs here + | _________| + | |_________| + | || +LL | || //~^ ERROR cannot borrow `self.thing` as mutable because it is also borrowed as immutable [E0502] +LL | || &self.number; + | || ---- previous borrow occurs due to use of `self` in closure +LL | || }); + | || ^ + | ||__________| + | |___________mutable borrow occurs here + | borrow later used here + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0502`. |
