Skip to content

Suggest 2021 edition upgrade on attempt to use disjoint capture #90157

Open
@jruderman

Description

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-closuresArea: Closures (`|…| { … }`)A-diagnosticsArea: Messages for errors, warnings, and lintsA-edition-2021Area: The 2021 editionT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions