Skip to content

Extra borrowing? #39908

Closed
Closed

Description

@GuillaumeGomez

So for the following code:

let tmp = if let (Ok(_src_path), Ok(_dest_path)) =
    (Path::new(&src_path).strip_prefix(&cur_dir),
     Path::new(&dest_path).strip_prefix(&cur_dir)) {
    (_src_path.to_path_buf(), _dest_path.to_path_buf())
} else {
    (src_path, dest_path)
};

I get the following error:

error[E0505]: cannot move out of `src_path` because it is borrowed
    --> src/libsyntax/parse/parser.rs:5249:30
     |
5245 |                             (Path::new(&src_path).strip_prefix(&cur_dir),
     |                                         -------- borrow of `src_path` occurs here
...
5249 |                             (src_path, dest_path)
     |                              ^^^^^^^^ move out of `src_path` occurs here

error[E0505]: cannot move out of `dest_path` because it is borrowed
    --> src/libsyntax/parse/parser.rs:5249:40
     |
5246 |                              Path::new(&dest_path).strip_prefix(&cur_dir)) {
     |                                         --------- borrow of `dest_path` occurs here
...
5249 |                             (src_path, dest_path)
     |                                        ^^^^^^^^^ move out of `dest_path` occurs here

error: aborting due to 2 previous errors

However, since we're out of the if scope, shouldn't I be able to use src_path and dest_path again?

Activity

  1. vitalyd commented on Feb 17, 2017

    @vitalyd

    You're hitting lexical borrow issue - rust-lang/rfcs#811.

  2. added
    C-bugCategory: This is a bug.
    A-NLLArea: Non-lexical lifetimes (NLL)
    on Jul 27, 2017
  3. added a commit that references this issue on Mar 11, 2019
    65cb35a
  4. added 3 commits that reference this issue on Apr 22, 2019
    bf0ea60
    c21fbfe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-NLLArea: Non-lexical lifetimes (NLL)A-borrow-checkerArea: The borrow checkerC-bugCategory: This is a bug.fixed-by-NLLBugs fixed, but only when NLL is enabled.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions