In the below code, I cannot understand why I'm getting this error: After all, it is just one consecutive sequence of calls, so there is no chance that the temp value will be accessed after that.
let file_name = PathBuf::from(output_file)
.file_name()
.ok_or(ZipError::FileNotFound)?
.to_str()
.ok_or(ZipError::FileNotFound)?;
error[E0716]: temporary value dropped while borrowed
--> src/internals/ops/ops_utils/zip.rs:18:21
|
18 | let file_name = PathBuf::from(output_file).file_name();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ - temporary value is freed at the end of this statement
| |
| creates a temporary which is freed while still in use
19 | let file_name = file_name
| --------- borrow later used here
|
= note: consider using a `let` binding to create a longer lived value