1

Title is probably a bit confusing, what I mean is that when I try to compile:

if folder_file_paths.len() > compressed_data.len() {
    compressed_data.reserve(folder_file_paths.len() - compressed_data.len() );
}

I get this error:

error[E0502]: cannot borrow `compressed_data` as immutable because it is also borrowed as mutable
   --> src/ImageMatching/main.rs:33:59
   |
33 |         compressed_data.reserve(folder_file_paths.len() - compressed_data.len() );
   |         ---------------                                   ^^^^^^^^^^^^^^^       - mutable borrow ends here
   |         |                                                 |
   |         mutable borrow occurs here                        immutable borrow occurs here

But I can't think of a reason why this is a problem, as shouldn't the argument be processed first, the resulting usize value be copied, and then the reserve function run?

When would the argument of a function be calculated after the actual function starts executing?

Edit: folder_file_path is a Vec, and compressed_data is a HashMap

8176135
  • 3,755
  • 3
  • 19
  • 42
  • Please can you include more information, such as the type of the objects. It looks like this is going to be because `compressed_data.reserve` takes a mutable self reference, but that isn't clear from the code you've provided. – Peter Hall May 31 '18 at 09:53
  • @PeterHall Added the types, but my question is that when a function takes a mutable reference, why does that affect what the arguments are, since it should be executed first. – 8176135 May 31 '18 at 09:57
  • @HandofC'thuhlu as you didn't include [mcve], we can only guess, take a look at the feature NLL, https://stackoverflow.com/q/50251487/7076153 – Stargateur May 31 '18 at 11:21

0 Answers0