Skip to content

MIR borrowck: wrong error for move into closure #46599

Closed
@vramana

Description

@vramana
# ramana at pc in ~/Documents/rust-lang/rust on git:fix-e0504 ✖︎ [18:05:33]
→ ./build/x86_64-unknown-linux-gnu/stage1/bin/rustc src/test/compile-fail/E0504.rs -Z borrowck=mir 
error[E0505]: cannot move out of `fancy_num` because it is borrowed
  --> src/test/compile-fail/E0504.rs:23:13
   |
21 |       let fancy_ref = &fancy_num;
   |                       ---------- borrow of `fancy_num` occurs here
22 | 
23 |       let x = move || {
   |  _____________^
24 | |         println!("child function: {}", fancy_num.num); //~ ERROR E0504
25 | |     };
   | |_____^ move out of `fancy_num` occurs here

error: aborting due to previous error


# ramana at pc in ~/Documents/rust-lang/rust on git:fix-e0504 ✖︎ [18:12:36]
→ ./build/x86_64-unknown-linux-gnu/stage1/bin/rustc src/test/compile-fail/E0504.rs                 
error[E0504]: cannot move `fancy_num` into closure because it is borrowed
  --> src/test/compile-fail/E0504.rs:24:40
   |
21 |     let fancy_ref = &fancy_num;
   |                      --------- borrow of `fancy_num` occurs here
...
24 |         println!("child function: {}", fancy_num.num); //~ ERROR E0504
   |                                        ^^^^^^^^^ move into closure occurs here

error: aborting due to previous error

cc @arielb1

I am working on this.

Metadata

Metadata

Assignees

Labels

A-NLLArea: Non-lexical lifetimes (NLL)C-enhancementCategory: An issue proposing an enhancement or a PR with one.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.NLL-diagnosticsWorking towards the "diagnostic parity" goal

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions