Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"temporary value dropped while borrowed" #3

Closed
matthew-a-thomas opened this issue Jul 16, 2019 · 2 comments
Closed

"temporary value dropped while borrowed" #3

matthew-a-thomas opened this issue Jul 16, 2019 · 2 comments
Milestone

Comments

@matthew-a-thomas
Copy link
Contributor

use ansi_rgb::{ Background, Foreground, red, green };

fn main() {
    let foo = "Hello, world!".fg(green()).bg(red());
    println!("{}", foo);
}

Output:

error[E0716]: temporary value dropped while borrowed
 --> src\main.rs:4:15
  |
4 |     let foo = "Hello, world!".fg(green()).bg(red());
  |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^          - temporary value is freed at the end of this statement
  |               |
  |               creates a temporary which is freed while still in use
5 |     println!("{}", foo);
  |                    --- borrow later used here
  |
  = note: consider using a `let` binding to create a longer lived value
@matthew-a-thomas matthew-a-thomas added this to the 0.2 milestone Jul 16, 2019
@bjorn3
Copy link

bjorn3 commented Jul 17, 2019

Maybe implement Foreground and Background for T instead of &T. I think it will most often be used on &str which is Copy already, so it doesnt get moved.

@matthew-a-thomas
Copy link
Contributor Author

@bjorn3 Great idea! Done in 6565959

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants