`Temporary freed while still in use` but only on Windows

So I was working with the crossterm crate in one of my projects the other day, and I got the follow error after using GitHub Actions to compile on Windows:

error[E0716]: temporary value dropped while borrowed
  --> src\???.rs:70:27
   |
68 | /         execute!(
69 | |             stdout,
70 | |             style::Print(&self.buffer.lock().unwrap().iter().collect::<String>())
   | |                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
71 | |         )?;
   | |         -
   | |         |
   | |_________temporary value is freed at the end of this statement
   |           borrow later used here
   |
   = note: consider using a `let` binding to create a longer lived value

error: aborting due to previous error

For more information about this error, try `rustc --explain E0716`.
error: could not compile `???`.

It of course worked when I switched the code to

if let Ok(rendered) = self.buffer.lock() {
    execute!(stdout, style::Print(rendered.iter().collect::<String>()))?;
}

but I was wondering why this only happened on Windows and why it wasn't a problem as I developed on Linux or when I compiled to Mac.

Am I just overlooking an issue in GitHub Actions or crossterm? Or is there an issue with Rust on Windows?

crossterm‘s macros produce different code on Windows than on unix.

1 Like

Yes, that would explain it, thank you!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.