Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 KB | None | 0 0
  1. #![allow(unreachable_code)]
  2.  
  3.  
  4. fn main() {
  5. println!("{:?}", {
  6. use std::convert::{TryFrom, TryInto}; struct NewType<'a, T>(&'a Vec<T>); impl<'a, T> TryFrom<&'a Vec<T>> for NewType<'a, T> { type Error = (); fn try_from(vec: &'a Vec<T>) -> Result<NewType<'a, T>, ()> { Ok(NewType(vec)) } } fn check<'a, T: 'a, V: 'static + TryInto<NewType<'a, T>>>(_: V) {} let vec: Vec<i32> = Vec::new(); check(&vec)
  7. });
  8. }
  9.  
  10.  
  11. /* ~~~~=== stderr ===~~~~
  12. Compiling playground v0.0.1 (/playground)
  13. error[E0597]: `vec` does not live long enough
  14. --> src/main.rs:6:339
  15. |
  16. 6 | use std::convert::{TryFrom, TryInto}; struct NewType<'a, T>(&'a Vec<T>); impl<'a, T> TryFrom<&'a Vec<T>> for NewType<'a, T> { type Error = (); fn try_from(vec: &'a Vec<T>) -> Result<NewType<'a, T>, ()> { Ok(NewType(vec)) } } fn check<'a, T: 'a, V: 'static + TryInto<NewType<'a, T>>>(_: V) {} let vec: Vec<i32> = Vec::new(); check(&vec)
  17. | ------^^^^-
  18. | | |
  19. | | borrowed value does not live long enough
  20. | argument requires that `vec` is borrowed for `'static`
  21. 7 | });
  22. | - `vec` dropped here while still borrowed
  23.  
  24. error: aborting due to previous error
  25.  
  26. For more information about this error, try `rustc --explain E0597`.
  27. error: Could not compile `playground`.
  28.  
  29. To learn more, run the command again with --verbose.
  30.  
  31. */
  32.  
  33. /* ~~~~=== stdout ===~~~~
  34.  
  35. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement