Skip to content

Fix variable name in E0502 double borrow error #51651

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/librustc_mir/borrow_check/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down
35 changes: 35 additions & 0 deletions src/test/ui/nll/issue-51268.rs
Original file line number Diff line number Diff line change
@@ -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]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are still checking for self.thing, which is probably also why the tests are failing ;)

Copy link
Contributor

@nikomatsakis nikomatsakis Jun 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that part is correct -- the main error still talks about self.thing.

&self.number;
});
}
}

fn main() {}
20 changes: 20 additions & 0 deletions src/test/ui/nll/issue-51268.stderr
Original file line number Diff line number Diff line change
@@ -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`.