Suggest 2021 edition upgrade on attempt to use disjoint capture #90157
Open
Description
opened on Oct 22, 2021
Given the following code, compiled using Rust 2018 edition:
fn main() {
let mut x = ("a".to_string(), "b".to_string());
let mut f = || x.0 += "...";
x.1 += "...";
f();
}
The current output is:
error[E0499]: cannot borrow `x.1` as mutable more than once at a time
--> src/main.rs:4:5
|
3 | let mut f = || x.0 += "...";
| -- --- first borrow occurs due to use of `x` in closure
| |
| first mutable borrow occurs here
4 | x.1 += "...";
| ^^^ second mutable borrow occurs here
5 | f();
| - first borrow later used here
For more information about this error, try `rustc --explain E0499`.
Ideally the output should look include:
Note: disjoint capture is available in Rust 2021 edition; see https://doc.rust-lang.org/edition-guide/rust-2021/disjoint-capture-in-closures.html
Activity