Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. #![allow(unreachable_code)]
  2.  
  3.  
  4. fn main() {
  5. println!("{:?}", {
  6. struct Config<'a> { host: &'a str } fn foo<'a>(config: &'a mut Config<'a>) { let value = serde_json::Value::String("bar.example.".to_owned()); if let Some(string) = value.as_str() { config.host = string; } }
  7. });
  8. }
  9.  
  10.  
  11. /* ~~~~=== stderr ===~~~~
  12. Compiling playground v0.0.1 (/playground)
  13. error[E0597]: `value` does not live long enough
  14. --> src/main.rs:6:174
  15. |
  16. 6 | struct Config<'a> { host: &'a str } fn foo<'a>(config: &'a mut Config<'a>) { let value = serde_json::Value::String("bar.example.".to_owned()); if let Some(string) = value.as_str() { config.host = string; } }
  17. | -- ^^^^^ -------------------- - `value` dropped here while still borrowed
  18. | | | |
  19. | | | assignment requires that `value` is borrowed for `'a`
  20. | lifetime `'a` defined here borrowed value does not live long enough
  21.  
  22. error: aborting due to previous error
  23.  
  24. For more information about this error, try `rustc --explain E0597`.
  25. error: Could not compile `playground`.
  26.  
  27. To learn more, run the command again with --verbose.
  28.  
  29. */
  30.  
  31. /* ~~~~=== stdout ===~~~~
  32.  
  33. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement