b3290d322e
A mutable and immutable borrow place some restrictions on what you can with the variable until the borrow ends. This commit attempts to convey to the user what those restrictions are. Also, if the original borrow is a mutable borrow, the error message has been changed (more specifically, i. "cannot borrow `x` as immutable because it is also borrowed as mutable" and ii. "cannot borrow `x` as mutable more than once" have been changed to "cannot borrow `x` because it is already borrowed as mutable"). In addition, this adds a (custom) span note to communicate where the original borrow ends.
19 lines
681 B
Rust
19 lines
681 B
Rust
// Copyright 2013 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.
|
|
|
|
use std::cell::RefCell;
|
|
|
|
fn main() {
|
|
let m = RefCell::new(0);
|
|
let mut b = m.borrow_mut();
|
|
let b1 = b.get();
|
|
let b2 = b.get(); //~ ERROR cannot borrow `b` because it is already borrowed as mutable
|
|
}
|